Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome DevTools: jump from XHR network request, to the code that made it

I want to debug a REST API and see how it's used from very complex client code. After I identify the AJAX request in the Network tab, how can I go to the code that created it?

enter image description here

Is this impossible?

like image 461
Dan Dascalescu Avatar asked Jan 06 '15 03:01

Dan Dascalescu


People also ask

What is XHR in network in Chrome?

XHR Breapoints allow you to break whenever a server request URL contains a particular value. Add an XHR breakpoint within the Sources tab. Click the + icon and enter a value to break on.

How do I change XHR in Chrome?

In the Network panel of devtools, right-click and select Copy as cURL. Paste / Edit the request, and then send it from a terminal, assuming you have the curl command.

How do I debug my XHR in Chrome?

Within Chrome, it's possible to place a breakpoint on a XmlHttpRequest allowing you to debug AJAX requests. You can add a breakpoint by going to the "Sources" tab and selecting "XHR Breakpoints". Click the plus icon and type part or all of the URL you wish to add a breakpoint for.


2 Answers

See the "Initiator" column in the network tab. It tells you which code initiated the AJAX call. You will also get a tooltip with a full stack trace.

Chrome DevTools Network Tab Initiator Stack Trace

like image 155
Konrad Dzwinel Avatar answered Oct 16 '22 06:10

Konrad Dzwinel


I don't have 50 reputation to comment so I'm replying to:

If you use a library like jQuery or Angular to help you make the call, is >there a way to see the source code that called the helper functions? – >Atav32 Mar 14 at 1:01

If you want to find "real" method call then add breakpoint in line suggested by "Initiator" column and hit "Step out of current function (Shift+F11)" till you reach code you want to.

Cheers!

like image 21
Maciej Bielski Avatar answered Oct 16 '22 05:10

Maciej Bielski