Skip to content

Commit

Permalink
fix: do actually catch worker initialization exceptions (#762)
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s authored Jan 30, 2020
1 parent 603b9f5 commit 1b012e5
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/webkit/wkWorkers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class WKWorkers {
helper.removeEventListeners(this._sessionListeners);
this.clear();
this._sessionListeners = [
helper.addEventListener(session, 'Worker.workerCreated', async (event: Protocol.Worker.workerCreatedPayload) => {
helper.addEventListener(session, 'Worker.workerCreated', (event: Protocol.Worker.workerCreatedPayload) => {
const worker = new Worker(event.url);
const workerSession = new WKSession(session.connection, event.workerId, 'Most likely the worker has been closed.', (message: any) => {
session.send('Worker.sendMessageToWorker', {
Expand All @@ -47,17 +47,14 @@ export class WKWorkers {
worker._createExecutionContext(new WKExecutionContext(workerSession, undefined));
this._page._addWorker(event.workerId, worker);
workerSession.on('Console.messageAdded', event => this._onConsoleMessage(worker, event));
try {
Promise.all([
workerSession.send('Runtime.enable'),
workerSession.send('Console.enable'),
session.send('Worker.initialized', { workerId: event.workerId }).catch(e => {
this._page._removeWorker(event.workerId);
})
]);
} catch (e) {
Promise.all([
workerSession.send('Runtime.enable'),
workerSession.send('Console.enable'),
session.send('Worker.initialized', { workerId: event.workerId })
]).catch(e => {
// Worker can go as we are initializing it.
}
this._page._removeWorker(event.workerId);
});
}),
helper.addEventListener(session, 'Worker.dispatchMessageFromWorker', (event: Protocol.Worker.dispatchMessageFromWorkerPayload) => {
const workerSession = this._workerSessions.get(event.workerId)!;
Expand Down

0 comments on commit 1b012e5

Please sign in to comment.