if (typeof SharedWorker !== "undefined") { const worker = new SharedWorker('/src/worker.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('当前浏览器不支持webworker') }