Skip to content

Commit

Permalink
fix: handle close
Browse files Browse the repository at this point in the history
  • Loading branch information
OrKoN committed Nov 29, 2023
1 parent 91e9af4 commit 5ee1a55
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/puppeteer-core/src/bidi/BidiOverCdp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export async function connectBidiOverCdp(
close(): void {
bidiServer.close();
cdpConnectionAdapter.close();
cdp.dispose();
},
onmessage(_message: string): void {
// The method is overridden by the Connection.
Expand Down Expand Up @@ -96,7 +97,11 @@ class CdpConnectionAdapter {
throw new Error(`Unknown CDP session with id ${id}`);
}
if (!this.#adapters.has(session)) {
const adapter = new CDPClientAdapter(session, id, this.#browserCdpConnection);
const adapter = new CDPClientAdapter(
session,
id,
this.#browserCdpConnection
);
this.#adapters.set(session, adapter);
return adapter;
}
Expand Down
3 changes: 3 additions & 0 deletions packages/puppeteer-core/src/bidi/Browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ export class BidiBrowser extends Browser {
return;
}
await this.#connection.send('browser.close', {});
await new Promise(resolve => {
setTimeout(resolve, 0);
});
this.#connection.dispose();
await this.#closeCallback?.call(null);
}
Expand Down
3 changes: 3 additions & 0 deletions packages/puppeteer-core/src/cdp/Connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ export class Connection extends EventEmitter<CDPSessionEvents> {
* @internal
*/
async closeBrowser(): Promise<void> {
if (this.#closed) {
return;
}
await this.send('Browser.close');
}

Expand Down

0 comments on commit 5ee1a55

Please sign in to comment.