//if (typeof SharedWorker !== "undefined") { // const worker = new SharedWorker('/src/SharedWorker.js') // worker.port.onmessage = (e) => { // console.log('worker.port.onmessage:', e.data) // } // worker.port.start() // const button = document.createElement('button') // button.innerText = 'click' // button.onclick = () => { // worker.port.postMessage('hello, worker') // } // document.body.appendChild(button) //} else { // console.log('当前浏览器不支持 SharedWorker') //} if ('serviceWorker' in navigator) { navigator.serviceWorker.register('/src/ServiceWorker.js').then(function (registration) { console.log('ServiceWorker registration successful with scope: ', registration.scope) }).catch(function (err) { console.log('ServiceWorker registration failed: ', err) }) } else { console.log('当前浏览器不支持 ServiceWorker') }