D
D
demon18062019-02-04 14:49:41
JavaScript
demon1806, 2019-02-04 14:49:41

Intercepting requests with "JS" in "Chrome" browser extension?

Good day! Can someone suggest, and ideally give examples of the implementation of this task: "Intercept the request, cancel it, and then display its url and headers on pages like this
You have requested ${url} URL
With the next headers: ${ listOfHeaders}
". Everything is created using "JS" as an extension under "Chrome".

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ihor Bratukh, 2019-02-04
@BRAGA96

Well, the scheme is something like this, proxying methods

(function () {
    'use strict';

    var original = {
        open: XMLHttpRequest.prototype.open,
        send: XMLHttpRequest.prototype.send
    };

    XMLHttpRequest.prototype.open = function (method, url, async, user, password) {
        console.log(url);
        return original.open.call(this, method, url, async, user, password);
    };

    XMLHttpRequest.prototype.send = function (data) {
        console.log(data);
        return original.send.call(this, data);
    };

}());

0
0ffff0, 2019-02-04
@0ffff0

Use the webRequest API to intercept HTTP requests . This API will allow you to add listeners at various stages of making HTTP requests. In listeners you can:

  1. get access to request headers and bodies, to response headers
  2. cancel and redirect requests
  3. modify request and response headers

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question