MCPcopy Index your code
hub / github.com/bbachi/react-dotnet-example / register

Function register

ClientApp/src/registerServiceWorker.js:21–44  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

19);
20
21export default function register () {
22 if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
23 // The URL constructor is available in all browsers that support SW.
24 const publicUrl = new URL(process.env.PUBLIC_URL, window.location);
25 if (publicUrl.origin !== window.location.origin) {
26 // Our service worker won't work if PUBLIC_URL is on a different origin
27 // from what our page is served on. This might happen if a CDN is used to
28 // serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374
29 return;
30 }
31
32 window.addEventListener('load', () => {
33 const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
34
35 if (isLocalhost) {
36 // This is running on localhost. Lets check if a service worker still exists or not.
37 checkValidServiceWorker(swUrl);
38 } else {
39 // Is not local host. Just register service worker
40 registerValidSW(swUrl);
41 }
42 });
43 }
44}
45
46function registerValidSW (swUrl) {
47 navigator.serviceWorker

Callers

nothing calls this directly

Calls 2

checkValidServiceWorkerFunction · 0.85
registerValidSWFunction · 0.85

Tested by

no test coverage detected