views:

125

answers:

3

How can I figure out where a request is made in a javascript application?

I'm debugging a large application which generates an incorrect HTTP request somewhere. I believe I haven't configured something properly with the API generating the request (Google Maps). If I could figure out where the request is made, then I could trace back to the construction of the URL and see where I need to set the right parameters.

Is it possible (in Safari/Chrome/Firefox with Firebug or anything else) to break at the point any request is made?

+1  A: 

Hi, If you're looking for a good plugin, you might find Tamper Data (for Firefox) really useful. Once you start 'Tamper', it will pop up a message box displaying all http POST details, including the values of various attributes.

keyboardP
+3  A: 

I am not sure if you could configure it to break on each request, but in FireBug you could use the Net and Console (for ajax) tabs to see a list of all outgoing requests.

Darin Dimitrov
+4  A: 

in firebug there's a new feature that lets you break when an XmlHttpRequest is made. you can then examine the stack to see who the caller is:

  • Break-on-XHR:

    Break On Next Network Event
    1. If you are stopped in the debugger, either click the blue continue button or reload the page
    2. Select the Firebug Net Panel
    3. Click the Break on Next or Pause button ()
    4. Click this button Break On XHR
    5. Firebug will break on the XHR event
    

In the case the request is made by way of regular dom manipulation (like an image tag being inserted), you could break when the DOM is changed:

The LiveHttpHeaders add-on could also be used to watch all HTTP requests and then you could grep the source for some identifiers used.

couple other ways to set a breakpoint in firebug:

  • insert this break statement into the code:

    debugger; 
    
  • open the script tab and select the line you want to break at

jspcal
Break-on-XHR was a good idea, but it turns out that the requests are under HTML subtab of 'Net' rather than the XHR subtab. Grepping seems to be the only way forward.
eaubin
Actually Firebug 1.5 beta does have what I want with the Tracing extension / NET_EVENTS turned on.
eaubin