Search code examples
javascriptgoogle-chromehttpfirefoxhttprequest

Forcing an HTTP request to fail in browser


Is it possible to make an http request that has been sent to a server by the browser fail without having to alter the javascript?

I have a POST request that my website is sending to the server and we are trying to test how our code reacts when the request fails (e.g. an HTTP 500 response). Unfortunately, the environment that I need to test it in has uglified and compressed javascript, so inserting a breakpoint or altering the javascript isn't an option. Is there a way for us to utilize any browser to simulate a failed request?

The request takes a long time to complete, so using the browser's console to run a javascript command is a possibility.

I have tried using window.stop(), however, this does not work since I need the failure code to execute.

I am aware of the option of setting up a proxy server, but would like to avoid this if possible.


Solution

  • In Chrome (just checked v63), you can actually block a specific URL (or even a whole domain) from the Network tab. You only need to right-click on the entry and select Block request URL (or Block request domain.)