MCPcopy Create free account
hub / github.com/FlowiseAI/Flowise / registerValidSW

Function registerValidSW

packages/ui/src/serviceWorker.js:21–62  ·  view source on GitHub ↗
(swUrl, config)

Source from the content-addressed store, hash-verified

19)
20
21function registerValidSW(swUrl, config) {
22 navigator.serviceWorker
23 .register(swUrl)
24 .then((registration) => {
25 registration.onupdatefound = () => {
26 const installingWorker = registration.installing
27 if (installingWorker == null) {
28 return
29 }
30 installingWorker.onstatechange = () => {
31 if (installingWorker.state === 'installed') {
32 if (navigator.serviceWorker.controller) {
33 // At this point, the updated precached content has been fetched,
34 // but the previous service worker will still serve the older
35 // content until all client tabs are closed.
36 console.info(
37 'New content is available and will be used when all tabs for this page are closed. See https://bit.ly/CRA-PWA.'
38 )
39
40 // Execute callback
41 if (config && config.onUpdate) {
42 config.onUpdate(registration)
43 }
44 } else {
45 // At this point, everything has been precached.
46 // It's the perfect time to display a
47 // "Content is cached for offline use." message.
48 console.info('Content is cached for offline use.')
49
50 // Execute callback
51 if (config && config.onSuccess) {
52 config.onSuccess(registration)
53 }
54 }
55 }
56 }
57 }
58 })
59 .catch((error) => {
60 console.error('Error during service worker registration:', error)
61 })
62}
63
64function checkValidServiceWorker(swUrl, config) {
65 // Check if the service worker can be found. If it can't reload the page.

Callers 2

checkValidServiceWorkerFunction · 0.85
registerFunction · 0.85

Calls 2

registerMethod · 0.65
catchMethod · 0.45

Tested by

no test coverage detected