Can an add-on add a service worker?

I would like to add service-worker caching to a website (not mine) so it will continue to work offline. I adapted service-worker registration code that works in my own website and built a test add-on.

Manifest:

  "content_scripts": [
      { "matches": ["https://michaeleskin.com/abctools/abctools.html"],
       "js": ["me_abc_caching.js"]}
    ],
  "background": {
    "scripts": ["service-worker.js"]
  }

Content script:

// Register service-worker
if('serviceWorker' in navigator) {
  let registration;
  const registerServiceWorker = async () => {
  serviceWorkerURL = browser.runtime.getURL('service-worker.js');
  console.log("SW URL: " + serviceWorkerURL);
  registration = await  navigator.serviceWorker.register(serviceWorkerURL);  
  };
  registerServiceWorker();
}

Registration fails ‘SecurityError: The operation is insecure’ - probably because the service worker file must be accessed over https not a local file, or part of an extension

I tried the same thing in Chrome and got a more definite error for the register(serviceWorkerURL):
origin of the provided scriptURL ('chrome-extension://fhhclgflaalhbhopkjjfobekbmpfjfob') does not match the current origin ('https://michaeleskin.com').

So I suspect that the answer to my question in the title is ‘no’.

Can anybody think of a way to achieve what I want to do?

I don’t know if that’s possible.
But maybe FF’s Offline Mode does what you need.

File > Work Offline

grafik

Offline mode would be hit-and-miss - whether a resource happened to be in the browser cache. And I want this to work on Android, which has no offline mode.