Closed SharikSaigal87 closed 3 years ago
Thanks @SharikSaigal87. I'm able to repro this with Chromium, but it works with WebKit and Firefox. Does that mirror your experience? Also, any particular reason for you to use Chrome stable (instead of Chromium)?
Modified snippet used for testing:
const {chromium, webkit, firefox} = require('playwright');
(async () => {
const browser = await chromium.launch({ headless: false });
await browser.newPage();
// Disconnected event should be fired when the browser is killed manually
browser.on('disconnected', () => { console.log('browser is closed') });
})();
Noticed that Chromium stays around in the process list even if the browser window is closed. Watching for the page closing event helps to workaround this, e.g.
import {chromium} from 'playwright';
(async () => {
const browser = await chromium.launch ({headless: false});
const context = await browser.newContext();
const page = await context.newPage();
page.on ('close', () => {
console.log ('page closed');
browser.close();});
})();
I'll rephrase this: in Chromium Headful, it's impossible to terminate chromium manually: closing last windows doesn't close browser, and Cmd-Q
doesn't close browser either.
Hmm... We keep the browser open, because Playwright script could open a new context at any moment.
Specifically on MacOS, where we have a separate "Quit application" command, we could theoretically make it quit anyway.
Seems like working as intended - I don't think we'll address this. When browser is controlled by Playwright, either call browser.close()
or just terminate the script.
As seen in below code snippet I am Not able to detect browser event: disconnected event when close browser is invoked.Butwhen node process is killed i get the event "browser is closed" Can you please help correct way of detectng browser disconnected event at correct time when browser is closed?
Context: Playwright Version: [playwright-v1.2.0] Operating System: [Windows (Pro 10 - 1809) & Linux (Ubuntu 20.04)] Node version: [v14.4.0 on Windows, v12.18.0 on Linux (Ubuntu 20.04)] Browser: [Chromium] Code Snippet