Skip to content

Close Browser and Close All Browsers hide why closing a browser failed #5323

Open

Description

@aaltat

Describe the bug
When closing a browser fails, Browser does not report the reason.

closeBrowser in node/playwright-wrapper/playwright-state.ts reports every failure as if the browser was already closed:

openBrowsers.popBrowser();
try {
    await currentBrowser.close();
    return stringResponse(currentBrowser.id, 'Closed browser');
} catch {
    return stringResponse('', `Browser ${currentBrowser.id} was already closed`);
}

PlaywrightState.closeAll, which Close Browser ALL and the automatic cleanup use, drops the error without a trace:

try {
    await browser.close();
} catch (e) {} // eslint-disable-line

BrowserState.close() stops tracing, closes the contexts and the browser, and since #5318 runs the onClose of an adopted context. A failure in any of these steps ends up in one of these two catch blocks. For example, a trace file that cannot be written, or an onClose that throws when it releases a device connection, shows up as "was already closed" or not at all.

Expected behavior
The test does not fail, because closing mostly happens in teardown or automatic cleanup, and the browser is removed from the stack either way. But the log shows the real error, so that a failing trace save or onClose can be found.

Possible fix
Log the caught error in closeBrowser and closeAll, and keep "was already closed" only for the case where the browser really was closed already.

Found while reviewing #5318 (adoptContext, #5317).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions