MCPcopy Create free account
hub / github.com/apitable/apitable / register

Function register

packages/datasheet/src/service_worker.ts:46–76  ·  view source on GitHub ↗
(config?: Config)

Source from the content-addressed store, hash-verified

44};
45
46export function register(config?: Config) {
47 if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
48 // The URL constructor is available in all browsers that support SW.
49 const publicUrl = new URL((process as { env: { [key: string]: string } }).env.PUBLIC_URL, window.location.href);
50 if (publicUrl.origin !== window.location.origin) {
51 // Our service worker won't work if PUBLIC_URL is on a different origin
52 // from what our page is served on. This might happen if a CDN is used to
53 // serve assets; see https://github.com/facebook/create-react-app/issues/2374
54 return;
55 }
56
57 window.addEventListener('load', () => {
58 const env = getEnvVariables();
59 const swUrl = `${env.NEXT_PUBLIC_PUBLIC_URL}/service-worker.js`;
60
61 if (isLocalhost) {
62 // This is running on localhost. Let's check if a service worker still exists or not.
63 checkValidServiceWorker(swUrl, config);
64
65 // Add some additional logging to localhost, pointing developers to the
66 // service worker/PWA documentation.
67 navigator.serviceWorker.ready.then(() => {
68 console.log('This web app is being served cache-first by a service ' + 'worker. To learn more, visit https://bit.ly/CRA-PWA');
69 });
70 } else {
71 // Is not localhost. Just register service worker
72 registerValidSW(swUrl, config);
73 }
74 });
75 }
76}
77
78function registerValidSW(swUrl: string, config?: Config) {
79 navigator.serviceWorker

Callers

nothing calls this directly

Calls 5

getEnvVariablesFunction · 0.90
checkValidServiceWorkerFunction · 0.85
registerValidSWFunction · 0.85
addEventListenerMethod · 0.65
logMethod · 0.45

Tested by

no test coverage detected