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

Function checkValidServiceWorker

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

Source from the content-addressed store, hash-verified

119}
120
121function checkValidServiceWorker (swUrl, config) {
122 // Check if the service worker can be found. If it can't reload the page.
123 window.fetch(swUrl, {
124 headers: { 'Service-Worker': 'script' }
125 })
126 .then(response => {
127 // Ensure service worker exists, and that we really are getting a JS file.
128 const contentType = response.headers.get('content-type')
129 if (
130 response.status === 404 ||
131 (contentType != null && !contentType.includes('javascript'))
132 ) {
133 // No service worker found. Probably a different app. Reload the page.
134 navigator.serviceWorker.ready.then(registration => {
135 registration.unregister().then(() => {
136 window.location.reload()
137 })
138 })
139 } else {
140 // Service worker found. Proceed as normal.
141 registerValidSW(swUrl, config)
142 }
143 })
144 .catch(() => {
145 console.log(
146 'No internet connection found. App is running in offline mode.'
147 )
148 })
149}
150
151export function unregister () {
152 if ('serviceWorker' in navigator) {

Callers 1

registerFunction · 0.85

Calls 6

registerValidSWFunction · 0.85
fetchMethod · 0.80
unregisterMethod · 0.80
getMethod · 0.65
logMethod · 0.65
reloadMethod · 0.45

Tested by

no test coverage detected