HTTP Request Sniffer

log http requests made with javascript in the console.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         HTTP Request Sniffer
// @namespace    HTTP Request Sniffer
// @version      1.0
// @description  log http requests made with javascript in the console.
// @author       Turtle ? Clan
// @license      GPL
// @match        *://*/*
// @grant        none
// @run-at       document-start
// ==/UserScript==
var createElement = function(tag, attributes, value) {
   var element       = document.createElement(tag);
   element.innerText = value || '';
   for ( var i = 0; attributes && i < attributes.length; i += 2 ) {
      element.setAttribute(attributes[i], attributes[i + 1]);
   }
   return element;
};

var injectScript = function(element, callback) {
   var script = createElement('script', ['type', 'text/javascript'], '(' + String(callback) + '())');
   element.appendChild(script);
};

var requestSniffer = function() {
   var self     = {};
   self.request = {};
   self.open    = XMLHttpRequest.prototype.open;
   self.send    = XMLHttpRequest.prototype.send;
   self.header  = XMLHttpRequest.prototype.setRequestHeader;
   XMLHttpRequest.prototype.open = function() {
      self.request         = {};
      self.request.method  = arguments['0'];
      self.request.url     = arguments['1'];
      self.request.headers = [];
      self.open.apply(this, arguments);
   };
   XMLHttpRequest.prototype.setRequestHeader = function() {
      self.request.headers.push(arguments['0']);
      self.request.headers.push(arguments['1']);
      self.header.apply(this, arguments);
   };
   XMLHttpRequest.prototype.send = function() {
      self.request.post = arguments['0'] || false;
      self.send.apply(this, arguments);
      console.log(self.request);
   };
};

injectScript(document.body || document.head || document.documentElement, requestSniffer);