Forcing HTTP request error in browser

Is it possible to make an HTTP request that was sent to the server by the browser without having to change javascript?

I have a POST request that my site sends to the server, and we are trying to check how our code responds when the request does not work (for example, an HTTP 500 response). Unfortunately, the environment in which I need to test it has compressed and compressed javascript, so inserting a breakpoint or changing javascript is not an option. Is there a way to use any browser to simulate a failed request?

The task takes a lot of time, so using the browser console to run a javascript command is an opportunity.

I tried using window.stop () , however this will not work, since I need to execute the error code.

I am aware of proxy settings, but I would like to avoid this.

+4
source share
5 answers

Chrome dev tools have the option to "decorate" (i.e. reindex) the JavaScript mini-code (click the "{}" button in the lower left). This can be combined with the "XHR breakpoint" option to break when the request is executed. XHR breakpoints do not support response modification, although AFAIK, but you must find a way to do this with code.

+1
source

: AJAX.

+3

XMLHttpRequest, . javascript AJAX URL- (, , 404):

XMLHttpRequest.prototype._old_open =
  XMLHttpRequest.prototype._old_open || XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {
  return XMLHttpRequest.prototype._old_open.call(
    this, method, 'TEST-'+url, async, user, pass);
};
+3

Chrome ( v63) URL ( ) "". Block request URL ( Block request domain.)

+2

Just enter the changed URL in the browser, for example. a well-formed URL, for example. http://thedomain.com/welcome/ with another "XX" location: http://thedomain.com/welcomeXX/ , which will result in a 404 error (not found)

-3
source

All Articles