Skip to content

The example for http-response did not work as expected  #415

@bugb

Description

@bugb

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    idleIssues and pull requests with no activity for three months.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions