Skip to content

Commit

Permalink
Listen to Target.detachedFromTarget instead of Target.targetDestroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s committed Mar 18, 2020
1 parent 04c7178 commit f7e31ca
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/chromium/crBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class CRBrowser extends platform.EventEmitter implements Browser {
const promises = [
session.send('Target.setDiscoverTargets', { discover: true }),
session.send('Target.setAutoAttach', { autoAttach: true, waitForDebuggerOnStart: true, flatten: true }),
session.send('Target.setDiscoverTargets', { discover: false }),
];
const existingPageAttachPromises: Promise<any>[] = [];
if (isPersistent) {
Expand Down Expand Up @@ -81,8 +82,8 @@ export class CRBrowser extends platform.EventEmitter implements Browser {
context._browserClosed();
this.emit(CommonEvents.Browser.Disconnected);
});
this._session.on('Target.targetDestroyed', this._targetDestroyed.bind(this));
this._session.on('Target.attachedToTarget', this._onAttachedToTarget.bind(this));
this._session.on('Target.detachedFromTarget', this._onDetachedFromTarget.bind(this));
this._firstPagePromise = new Promise(f => this._firstPageCallback = f);
}

Expand Down Expand Up @@ -151,11 +152,11 @@ export class CRBrowser extends platform.EventEmitter implements Browser {
return { context, target };
}

async _targetDestroyed(event: { targetId: string; }) {
const target = this._targets.get(event.targetId)!;
_onDetachedFromTarget({targetId}: Protocol.Target.detachFromTargetParameters) {
const target = this._targets.get(targetId!)!;
if (!target)
return;
this._targets.delete(event.targetId);
this._targets.delete(targetId!);
target._didClose();
}

Expand Down

0 comments on commit f7e31ca

Please sign in to comment.