chrome.webRequest.onBeforeRequest.addListener

1,190 views
Skip to first unread message

Marcus Stricker

unread,
Feb 7, 2021, 1:25:53 PM2/7/21
to Chromium Extensions
Hello

i came from firebird there it works fine.
Now in chrome it does not work
whats wrong ?

function listener(details) {
  var tmp = "";
  if (details.url.substring(0,42) == 'https://myurl/json?') {
    var filter = chrome.webRequest(details.requestId); 
    var decoder = new TextDecoder("utf-8");
    var encoder = new TextEncoder();
    filter.ondata = event => {
      var str = decoder.decode(event.data, {stream: true});
      console.log('part ' + str);
      filter.write(encoder.encode(str));
      filter.onstop = event => {
        console.log('komplete ' + tmp);
        filter.disconnect();
      };
      tmp = tmp + str;
    };
  };
  return {};
};

chrome.webRequest.onBeforeRequest.addListener(
  listener,
  {urls: ["<all_urls>"], types: ["xmlhttprequest"]},
  ["blocking"]
);

Thanks br marcus

Marcus Stricker

unread,
Feb 7, 2021, 1:26:54 PM2/7/21
to Chromium Extensions, Marcus Stricker
sorry the error is chrome.webRequest is not a function

Marcus Stricker

unread,
Feb 8, 2021, 1:57:52 PM2/8/21
to Chromium Extensions, Marcus Stricker

can i gife more informaton for an answer 

ilyaigpetrov

unread,
Feb 9, 2021, 6:27:33 AM2/9/21
to Chromium Extensions, m...@dmst.de
> var filter = chrome.webRequest(details.requestId); 

Please, show me a documentation or an example where this usage of chrome.webRequest is described. I've never seen such usage before.

Marcus Stricker

unread,
Feb 9, 2021, 6:32:09 PM2/9/21
to Chromium Extensions, ilyaigpetrov, Marcus Stricker
it stand no where ... it is my idea because it works in firefox fine. 
i seach for the chrome version to read the result from a page ..

thanks br caddy

Simeon Vincent

unread,
Feb 10, 2021, 10:04:33 PM2/10/21
to Marcus Stricker, Chromium Extensions, ilyaigpetrov
I don't see mention of this usage pattern in Mozilla's webRequest docs either. The closest thing I can find is browser.webRequest.filterResponseData, which is a Firefox-only construct. Chrome does not currently allow extensions to modify response bodies (feature request) and it's unlikely we'll add this as we're moving to another network request modification API: declarativeNetRequest.

If you want to transform the response body of a request, I think your best bet may be to implement that in a proxy server.

Cheers,

Simeon - @dotproto
Chrome Extensions DevRel


--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/ceb7a185-2a40-4c04-b093-f49046d548e2n%40chromium.org.
Reply all
Reply to author
Forward
0 new messages