A listener for all XMLHttpRequest
requests in the browser.
Implemented by monkey patching window.XMLHttpRequest
.
npm i on-xmlhttprequest
request
is an event emitter withmethod
andurl
properties. Also hasxhr
property which is the originalXMLHttpRequest
object
var onXhr = require('on-xmlhttprequest');
onXhr(function (request) {
console.log(request.method, request.url);
console.log(request.xhr); // just the original XMLHttpRequest
request.on('open', function () {
console.log('open');
});
request.on('done', function (response) {
console.log('done', response.status, response.responseText);
});
request.on('abort', function () {
console.log('abort');
});
request.on('timeout', function () {
console.log('timeout');
});
request.on('error', function () {
console.log('error');
});
});