Skip to content

Commit

Permalink
fix error event handler for shared worker
Browse files Browse the repository at this point in the history
  • Loading branch information
jerry2013 authored May 30, 2024
1 parent ee2b6e5 commit 24837a3
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/web/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,12 @@ const startWorker = ({
}) => {
try {
if (type === TYPE_SHARED_WORKER) {
workerPort = new window.SharedWorker(workerUrl, workerOptions).port
const worker = new window.SharedWorker(workerUrl, workerOptions)
worker.addEventListener('error', (event) => options.onError?.(event))
workerPort = worker.port
} else {
workerPort = new window.Worker(workerUrl, workerOptions)
workerPort.addEventListener('error', (event) => options.onError?.(event))
}
} catch (e) {
return reject(e)
Expand All @@ -93,10 +96,7 @@ const startWorker = ({
}

workerPort.addEventListener('message', (event) => handleWorkerMessages({ event, options }))
if (options.onError) {
workerPort.addEventListener('error', (event) => options.onError(event.toString()))
workerPort.addEventListener('messageerror', (event) => options.onError(event.toString()))
}
workerPort.addEventListener('messageerror', (event) => options.onError?.(event))

if (type === TYPE_SHARED_WORKER) {
workerPort.start() // we need start port only for shared worker
Expand Down

0 comments on commit 24837a3

Please sign in to comment.