Reputation: 13003
Using Google Chrome, I would like to break before a specified XMLHttpRequest event is fired in order to manipulate its arguments data.
So far, I managed to to break on an XHR call event, but I couldn't figure out how to manipulate the call's input before it is fired and sent to the server - my main goal is to manipulate/change the argument of the request.
Here is a snapshot of my current work using the Chrome DevTools:
Any help would be appriciated!
Upvotes: 2
Views: 1542
Reputation: 25897
Have you tried the XHR Breakpoints feature on the Sources panel? I'm pretty sure that'll break before the request is sent out. From there you can inspect and manipulate the data from the Console.
You can see the pane on the right of the screenshot above.
Another way to set breakpoints on XHRs is from the Event Listener Breakpoints pane. From here you can trigger breakpoints on various stages of the XHR lifecycle.
Take the following fiddle for example: https://jsfiddle.net/kaycebasques/jdf20gn4/1/
var xhr = new XMLHttpRequest();
var params = {"a": 1, "b": 2};
xhr.open('GET', 'https://httpbin.org/get');
xhr.send(params);
I created the "Any XHR" breakpoint by pressing the plus sign next to XHR Breakpoints and then just pressing Enter
.
When the breakpoint is paused, you can see the currently defined variables in the Scope pane, above XHR Breakpoints.
To modify XHR data, you just find the variable that you're looking for in the Scope pane, and then use the Console to modify that variable.
Upvotes: 5