Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve GET requests with Javascript in Firefox console

Is there a way to retrieve details of GET requests of a web page using JavaScript? I don't mean parameters of the current page's URL but out-going GET requests.

Example: If you open google's start page with firefox and toggle developer-tools, in the network tab you can see a number of GET request such as that for the logo which is something like https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png

I want to retrieve this URL on console tab using JavaScript. Is it possible to retrieve it via an object attached to the DOM (document) or BOM (window)?

The reason for my question is: I am in an test automation environment where developer-tools are not available. Only JavaScript is available and I need to check the URL of a GET request issued by the current page. I just mentioned developer-tools because it is the simplest way to reproduce the problem (and the easiest way to verify, if a solution works). But it is more about Firefox/HTTP than test automation as such.

like image 309
Würgspaß Avatar asked Jan 06 '16 09:01

Würgspaß


People also ask

How do I use JavaScript console in Firefox?

You can open the Browser Console in one of two ways: from the menu: select “Browser Console” from the Browser Tools submenu in the Firefox Menu (or Tools menu if you display the menu bar or are on macOS). from the keyboard: press Ctrl + Shift + J (or Cmd + Shift + J on a Mac).

How do I view HTTP Headers in Firefox?

In the Network tab, right-click the element you wish to inspect and select Save All As HAR. In this view, the HTTP headers are also visible in the Headers box on the right-hand side.


1 Answers

I don't think it's possible within devtools, but you may be able to use normal JS to make a global event handler (if it's jQuery) or if using normal JS, replace the XmlHttpRequest object with a duckpunched object that logs the result, as described here.

like image 95
NoBugs Avatar answered Sep 24 '22 14:09

NoBugs