MCPcopy
hub / github.com/realdennis/md2pdf / register

Function register

src/serviceWorkerRegistration.js:21–53  ·  view source on GitHub ↗
(config)

Source from the content-addressed store, hash-verified

19);
20
21export function register(config) {
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.href);
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/facebook/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. Let's check if a service worker still exists or not.
37 checkValidServiceWorker(swUrl, config);
38
39 // Add some additional logging to localhost, pointing developers to the
40 // service worker/PWA documentation.
41 navigator.serviceWorker.ready.then(() => {
42 console.log(
43 'This web app is being served cache-first by a service ' +
44 'worker. To learn more, visit https://cra.link/PWA'
45 );
46 });
47 } else {
48 // Is not localhost. Just register service worker
49 registerValidSW(swUrl, config);
50 }
51 });
52 }
53}
54
55function registerValidSW(swUrl, config) {
56 navigator.serviceWorker

Callers

nothing calls this directly

Calls 2

checkValidServiceWorkerFunction · 0.85
registerValidSWFunction · 0.85

Tested by

no test coverage detected