webextensions-examples icon indicating copy to clipboard operation
webextensions-examples copied to clipboard

The example for http-response did not work as expected

Open bugb opened this issue 6 years ago • 2 comments

I tried to load the extension after clone the code from this link:

https://github.com/mdn/webextensions-examples/tree/master/http-response

After that I see the extension does not work, the domain example.com is not used anymore. The I tried to change the code to something like this:

function listener(details) {
  let filter = browser.webRequest.filterResponseData(details.requestId);
  let decoder = new TextDecoder("utf-8");
  let encoder = new TextEncoder();

  filter.ondata = event => {
    let str = decoder.decode(event.data, {stream: true});
    // Just change any instance of Example in the HTTP response
    // to WebExtension Example.
    str = str.replace(/^.*$/g, 'WebExtension Example');
    filter.write(encoder.encode(str));
    filter.disconnect();
  }

  return {};
}

browser.webRequest.onBeforeRequest.addListener(
  listener,
  {urls: ["https://google.com/*"], types: ["main_frame"]},
  ["blocking"]
);

But the extension still not work as expected.

Can you please take a look the problem for me?

bugb avatar Jun 04 '19 11:06 bugb

What do you mean with "[...] the domain example.com is not used anymore"? It is available since roughly 20 years and still can be used for demonstrating examples.

To make your version with google.com working you'll need to add google to the manifest here: https://github.com/mdn/webextensions-examples/blob/master/http-response/manifest.json#L13

Otto-AA avatar Jun 13 '19 08:06 Otto-AA

I was recently working on a pull request to improve the http-response example (#460) and I can confirm that this extension was working as expected before I made any changes to it, so I don't think there is likely an issue. @bugb Have you tried it recently?

wingman-jr-addon avatar Nov 07 '20 03:11 wingman-jr-addon

Assumed resolved as no further comment for 3 years

rebloor avatar Jun 24 '23 16:06 rebloor