MCPcopy
hub / github.com/DesignRevision/shards-dashboard-react / register

Function register

src/serviceWorker.js:23–55  ·  view source on GitHub ↗
(config)

Source from the content-addressed store, hash-verified

21);
22
23export function register(config) {
24 if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
25 // The URL constructor is available in all browsers that support SW.
26 const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
27 if (publicUrl.origin !== window.location.origin) {
28 // Our service worker won't work if PUBLIC_URL is on a different origin
29 // from what our page is served on. This might happen if a CDN is used to
30 // serve assets; see https://github.com/facebook/create-react-app/issues/2374
31 return;
32 }
33
34 window.addEventListener('load', () => {
35 const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
36
37 if (isLocalhost) {
38 // This is running on localhost. Let's check if a service worker still exists or not.
39 checkValidServiceWorker(swUrl, config);
40
41 // Add some additional logging to localhost, pointing developers to the
42 // service worker/PWA documentation.
43 navigator.serviceWorker.ready.then(() => {
44 console.log(
45 'This web app is being served cache-first by a service ' +
46 'worker. To learn more, visit http://bit.ly/CRA-PWA'
47 );
48 });
49 } else {
50 // Is not localhost. Just register service worker
51 registerValidSW(swUrl, config);
52 }
53 });
54 }
55}
56
57function registerValidSW(swUrl, config) {
58 navigator.serviceWorker

Callers

nothing calls this directly

Calls 2

checkValidServiceWorkerFunction · 0.85
registerValidSWFunction · 0.85

Tested by

no test coverage detected