Skip to content

Commit

Permalink
chore: detach on userSession only
Browse files Browse the repository at this point in the history
  • Loading branch information
Lightning00Blade committed Mar 26, 2024
1 parent ae53ee1 commit 36bbdbf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions packages/puppeteer-core/src/bidi/CDPSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ export class BidiCdpSession extends CDPSession {
static sessions = new Map<string, BidiCdpSession>();

#detached = false;
#userCreated: boolean;
readonly #connection: BidiConnection | undefined = undefined;
readonly #sessionId = Deferred.create<string>();
readonly frame: BidiFrame;

constructor(frame: BidiFrame, sessionId?: string) {
constructor(frame: BidiFrame, sessionId?: string, userCreated = false) {
super();
this.frame = frame;
this.#userCreated = userCreated;
if (!this.frame.page().browser().cdpSupported) {
return;
}
Expand Down Expand Up @@ -86,10 +88,13 @@ export class BidiCdpSession extends CDPSession {
if (this.#connection === undefined || this.#detached) {
return;
}

try {
await this.frame.client.send('Target.detachFromTarget', {
sessionId: this.id(),
});
if (this.#userCreated) {
await this.frame.client.send('Target.detachFromTarget', {
sessionId: this.id(),
});
}
} finally {
BidiCdpSession.sessions.delete(this.id());
this.#detached = true;
Expand Down
2 changes: 1 addition & 1 deletion packages/puppeteer-core/src/bidi/Frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ export class BidiFrame extends Frame {
flatten: true,
});
await this.browsingContext.subscribe([Bidi.ChromiumBidi.BiDiModule.Cdp]);
return new BidiCdpSession(this, sessionId);
return new BidiCdpSession(this, sessionId, true);
}

@throwIfDetached
Expand Down

0 comments on commit 36bbdbf

Please sign in to comment.