diff --git a/packages/playwright-core/src/server/bidi/bidiPage.ts b/packages/playwright-core/src/server/bidi/bidiPage.ts index e27bbfca7dc5d..757a269c6d701 100644 --- a/packages/playwright-core/src/server/bidi/bidiPage.ts +++ b/packages/playwright-core/src/server/bidi/bidiPage.ts @@ -390,10 +390,17 @@ export class BidiPage implements PageDelegate { } async closePage(runBeforeUnload: boolean): Promise { - await this._session.send('browsingContext.close', { + const onClose = this._session.send('browsingContext.close', { context: this._session.sessionId, promptUnload: runBeforeUnload, }); + + // Only wait for the browsingContext to close if runBeforeUnload is false. + // Otherwise a before unload prompt might be displayed and should be handled + // by the caller. + // See NOTE on https://playwright.dev/docs/api/class-page#page-close + if (!runBeforeUnload) + await onClose; } async setBackgroundColor(color?: { r: number; g: number; b: number; a: number; }): Promise { diff --git a/tests/bidi/expectations/bidi-chromium-library.txt b/tests/bidi/expectations/bidi-chromium-library.txt index aad83691f69b1..091e3a58e4afa 100644 --- a/tests/bidi/expectations/bidi-chromium-library.txt +++ b/tests/bidi/expectations/bidi-chromium-library.txt @@ -1,5 +1,3 @@ -library/beforeunload.spec.ts › should access page after beforeunload [timeout] -library/beforeunload.spec.ts › should run beforeunload if asked for @smoke [timeout] library/browsercontext-events.spec.ts › console event should work in immediately closed popup [timeout] library/browsercontext-events.spec.ts › console event should work in popup 2 [timeout] library/browsercontext-events.spec.ts › dialog event should work in immediately closed popup [timeout]