Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 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,15 @@ 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 => {
this._page._removeWorker(event.workerId);
})
]).catch(e => {
// Worker can go as we are initializing it.
}
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we call page._removeWorker here, and not in line 54?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Done.

}),
helper.addEventListener(session, 'Worker.dispatchMessageFromWorker', (event: Protocol.Worker.dispatchMessageFromWorkerPayload) => {
const workerSession = this._workerSessions.get(event.workerId)!;
Expand Down