Cancel a Request and Fake a Response

I am writing an addon that replaces the code served by a particular URL. This is similar to the page-eater.js addon: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Modify_a_web_page

In the example above, the request still completes, which adds latency for the user. Instead of making the request and changing the result, I would like to reduce overall latency by canceling the request and providing a faked response.

In my attempts so far, any time that I cancel the request I also lose all opportunity to provide a faked result.

Maybe it would be more efficient to redirect to a page in your add-on? The webRequest API allows that:

Thanks for the suggestion! I don’t think a redirect works though because we want the page that gets loaded to remain in the same subdomain as the original, so that it shares access to cookies and localstorage with all other pages in the subdomain, but is isolated from pages in other subdomains.