Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cancel ajax request from chrome developer tools

I want to cancel the ajax request from chrome developer tools after it has initiated. For example I want to test my fallback message is showing correctly. I can set No throttling to Offline so that all calls will fail, but I just want to test one API to fail, for debugging purposes.

Developer tools

I know I can use abort() methods, (ie I can do it through JavaScript). I dont want to touch the code for just this need.

There's a replay XHR option in right click of the API, It'll be great there is something like abort XHR in same way. But there isn't.

like image 698
Asim K T Avatar asked Feb 27 '16 05:02

Asim K T


People also ask

How do I turn off dev tools request?

To use Request Blocking in DevTools: Right click on a resource in the Network Panel. Select Block request URL - this resource is now excluded from subsequent page loads.

How do I stop DevTools from popping up in Chrome?

Start Google Chrome with the “—disable-dev-tools” command line switch to prevent the “Developer Tools” feature from running.


2 Answers

From Chrome 59 you can block specific requests from Network tab of developer tools itself.

https://developers.google.com/web/updates/2017/04/devtools-release-notes#block-requests

Right-click on the request in the Network panel and select Block Request URL. A new Request blocking tab pops up in the Drawer, which lets you manage blocked requests.

So, In my case, I will run the code block that specific API and then re-run. :)

As per the comment, this is not exactly canceling the already started request, but checking how the app behaves if only one request is failed by blocking only one request. Thanks @Ross Ivantsiv for this.

screenshot for blocking request

like image 123
Asim K T Avatar answered Oct 04 '22 05:10

Asim K T


There is a simple trick I use. Pressing F5 while in the tab immediately followed by ESC.

XHR requests still active by chrome are canceled before the new answer is loaded.

like image 40
Mehmet Ali Uysal Avatar answered Oct 04 '22 04:10

Mehmet Ali Uysal