Original fetch.
window.fetch will be replaced to customized fetch on xspy.enable() called.
Regardless of whether xspy.enable() called, xspy.OriginalFetch always returns original fetch.
Original XMLHttpRequest.
window.XMLHttpRequest will be replaced to customized XMLHttpRequest on xspy.enable() called.
Regardless of whether xspy.enable() called, xspy.OriginalXHR always returns original XMLHttpRequest.
Remove all request/response listeners.
Remove all request listeners.
Remove all response listeners.
Stop to listen request/response.
It replaces back to original XMLHttpRequest and window.fetch.
Start to listen request/response from XMLHttpRequest/fetch.
Request/Response hook is enabled by replacing XMLHttpRequest and window.fetch to the ones in this library.
Note: This does not polyfill window.fetch for Internet Explorer which does not originally implement window.fetch.
Get an array of request listeners. Note that any operations (push/pop/unshift/shift) on the array does not affect saved listeners.
Get an array of response listeners.
Check xspy is enabled and listening request/response.
Remove a request listener.
Remove a response listener.
Add custom request listener to index n. (listener at index n=0 will be called first)
If you do not specify n, it appends listener to the last. (Called after all previous listeners finishes.)
This listener will be called just before web request by window.fetch() or xhr.sent() departs from browser.
You can modify the request object(i.e. headers, body) before it is sent.
Note that when you supplies listener as 2 parameters function(request and callback),
request will not be dispatched until you manually run callback() function in handler.
If you run callback() without any arguments or with non-object value like false,
request processing goes forward without generating fake response.
If you run callback(res) with a fake response object, it immediately returns the fake response after all onRequest listeners
finishes. In this case, real request never flies to any external network.
Add custom response listener to index n. (listener at index n=0 will be called first)
If you do not specify n, it appends listener to the last. (Called after all previous listeners finishes.)
This listener will be called just before API response is available at
window.fetch().then(res => ...) or xhr.onreadystatechange, and so on.
You can modify the response object before it is available to the original requester.
Note that when you supplies listener as 3 parameters function(request, response and callback),
response will not be returned to the original requester until you manually run callback() function in handler.
Generated using TypeDoc
After a document loads
XSpyclass, it is available by callingwindow.xspyor justxspy.Note: Not
window.XSpybutwindow.xspy. (All lower characters)xspy