MCPcopy Index your code
hub / github.com/SeleniumHQ/selenium / registerValidSW

Function registerValidSW

javascript/grid-ui/src/serviceWorker.ts:77–119  ·  view source on GitHub ↗
(swUrl, config)

Source from the content-addressed store, hash-verified

75}
76
77function registerValidSW (swUrl, config) {
78 navigator.serviceWorker
79 .register(swUrl)
80 .then(registration => {
81 registration.onupdatefound = () => {
82 const installingWorker = registration.installing
83 if (installingWorker == null) {
84 return
85 }
86 installingWorker.onstatechange = () => {
87 if (installingWorker.state === 'installed') {
88 if (navigator.serviceWorker.controller != null) {
89 // At this point, the updated precached content has been fetched,
90 // but the previous service worker will still serve the older
91 // content until all client tabs are closed.
92 console.log(
93 'New content is available and will be used when all ' +
94 'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
95 )
96
97 // Execute callback
98 if (config && config.onUpdate) {
99 config.onUpdate(registration)
100 }
101 } else {
102 // At this point, everything has been precached.
103 // It's the perfect time to display a
104 // "Content is cached for offline use." message.
105 console.log('Content is cached for offline use.')
106
107 // Execute callback
108 if (config && config.onSuccess) {
109 config.onSuccess(registration)
110 }
111 }
112 }
113 }
114 }
115 })
116 .catch(error => {
117 console.error('Error during service worker registration:', error)
118 })
119}
120
121function checkValidServiceWorker (swUrl, config) {
122 // Check if the service worker can be found. If it can't reload the page.

Callers 2

registerFunction · 0.85
checkValidServiceWorkerFunction · 0.85

Calls 2

registerMethod · 0.65
logMethod · 0.65

Tested by

no test coverage detected