Anvil Service Worker Question

You won’t be able to have access to the existing service worker.

Have you tried creating your own service worker?

You could create a file in your assets, sw.js, and register this as an additional service worker.
Then in native libraries something like:

<!-- Native Libraries -->
<script>
    async function registerServiceWorker() {
        try {
            const registration = await navigator.serviceWorker.register("_/theme/sw.js");
            if (registration.installing) {
                console.log("%cService worker installing", "color: orange;");
            } else if (registration.active) {
                console.log("%cService worker active", "color: green;");
            }
        } catch (err) {
            console.error(`Registration failed with ${err}`);
        }
    }
    registerServiceWorker();
</script>
1 Like