6

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.

Würgspaß
  • 4,660
  • 2
  • 25
  • 41
  • Maybe this can help: http://stackoverflow.com/questions/5448545/how-to-retrieve-get-parameters-from-javascript – parameciostudio Jan 07 '16 at 12:45
  • @parameciostudio No, I had a look at that already. But this is not the point here: As I said I do not want to retrieve the parameters of the page that is shown in Firefox but the requests **issued by that page** and which are listed in the network analysis tab. – Würgspaß Jan 07 '16 at 12:50

1 Answers1

1

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.

NoBugs
  • 9,310
  • 13
  • 80
  • 146
  • I like the second approach but I am unable to verify because I can't change the server. If I try in my browser, edit the page, insert the additional script and resend the request there is some warning about blocked "Cross-Origin" request. – Würgspaß Jan 07 '16 at 16:22
  • Can you post the script and exact error message you're getting? Are you sure you're not having problems due to CORS in the first place? – NoBugs Jan 08 '16 at 01:33
  • Well, yes it is due to CORS. My manually sent request is blocked due to: "Missing CORS header: Access-Control-Allow-Origin missing". The requested server is not under my control, so I'm stuck. Anyway, if time permits, I will try to set up a different minimalistic environment to thoroughly test this approach. – Würgspaß Jan 11 '16 at 08:04