Skip to content

Service worker (workbox) with android webview error #410

@JohnRSim

Description

@JohnRSim

Not sure if this is the same -
https://bugs.chromium.org/p/chromium/issues/detail?id=977784

I get the following error in the browser console -

An unknown error occurred when fetching the script.
(index):1 Uncaught (in promise) TypeError: Failed to register a ServiceWorker: An unknown error occurred when fetching the script.

This works fine from the browser using localhost

config.xml

        <preference name="Hostname" value="test" />
        <preference name="Scheme" value="https" />

index.html

<script>
if (('serviceWorker' in navigator) && (window.location.href.indexOf('file://') <= 0)) {
	  // Use the window load event to keep the page load performant
	  window.addEventListener('load', () => {
		navigator.serviceWorker.register('sw2.js');
	  });
}
</script>

sw2.js

importScripts("workbox-v4.3.1/workbox-sw.js");
workbox.setConfig({modulePathPrefix: "workbox-v4.3.1"});

workbox.core.setCacheNameDetails({prefix: "smartr-cache"});

workbox.core.skipWaiting();

workbox.core.clientsClaim();

/**
 * The workboxSW.precacheAndRoute() method efficiently caches and responds to
 * requests for URLs in the manifest.
 * See https://goo.gl/S9QRab
 */
self.__precacheManifest = [
  {
    "url": "js/appConfig.js",
    "revision": "0aa8bda62dc6167427c992a9dc82bb53"
  },
  {
    "url": "js/appConfigExternal.json",
    "revision": "8f2d9e22d885f3af63b4c56e1abb6717"
  },
  {
    "url": "js/appController.js",
    "revision": "8d25c1032f1b9d0f0c16148ab74381a3"
  },
  {
    "url": "js/cordovaMocks.js",
    "revision": "28660184e9244efec9986d56fdb26b31"
  },
  {
    "url": "js/jet.js",
    "revision": "448bda08ee98cbbac4592dd974f96936"
  }
].concat(self.__precacheManifest || []);
workbox.precaching.precacheAndRoute(self.__precacheManifest, {});

workbox.precaching.cleanupOutdatedCaches();

workbox.routing.registerRoute(/^https:\/\/mydomain.com/, new workbox.strategies.StaleWhileRevalidate({ "cacheName":"mytest-images-uat", plugins: [new workbox.cacheableResponse.Plugin({ statuses: [ 0, 200 ] })] }), 'GET');

If you want I can create a basic example and source of clean cordova / ionic project.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions