Completely replacing a request in a WebExtension

Viewed 127

I'm looking to make a web extension for Firefox that stores HTML pages and other resources in local storage and serves them for offline viewing. To do that, I need to intercept requests that the browser makes for the pages and the content in them.

Problem is, I can't figure out how to do that. I've tried several approaches:

  • The webRequest API doesn't allow fulfilling a request entirely - it can only block or redirect a request, or edit the response after it's been done.
  • Service Workers can listen to the fetch event, which can do what I want, but calling navigator.serviceWorker.register in an addon page (the moz-extension://<id> domain) results in an error: DOMException: The operation is insecure. Relevant Firefox bug
  • I could possibly set up the service worker on a self hosted domain with a content script, but then it won't be completely offline.

Is there an API that I missed that can intercept requests from inside a web extension?

0 Answers
Related