fix: do actually catch worker initialization exceptions (#762)

This commit is contained in:
Yury Semikhatsky 2020-01-30 11:40:56 -08:00 committed by GitHub
parent 603b9f54dd
commit 1b012e50e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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', {
@ -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)!;