Skip to content

Instantly share code, notes, and snippets.

@magic890
magic890 / js_xmlhttprequest_interceptor.js
Last active February 11, 2020 14:30
JS HTTP request interceptor
// Intercept all the HTTP requests and inject a tracker if the payload is JSON
!function() {
XMLHttpRequest.prototype._original_send = XMLHttpRequest.prototype.send;
let interceptor_send = function(data) {
try {
obj = JSON.parse(data);
obj._tracker = 'tracker_id';
let new_data = JSON.stringify(obj);
this._original_send(new_data);