How to register service workers on iOS Capacitor apps?

Capacitor is telling me

:high_voltage: [error] - [App] Service worker registration failed: TypeError serviceWorker.register() must be called with a script URL whose protocol is either HTTP or HTTPS {}

but obviously the protocol in a capacitor app is capacitor://

So how can I register service workers in a capacitor app?

Actually all I want is to intercept every single request, and if it is a same-origin request, handle it with custom behaviour depending on the path. For example <img src="/media/image.png"> should load the image from https://mywebsite.com/media/image.png instead of from capacitor://localhost/media/image.png

You can’t. Service Workers fail in Capacitor because browser engines only allow them on https or http://localhost, while Capacitor uses a custom capacitor:// protocol.