-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Playwright can not close the browser when running with Chrome (no-headless mode) #5327
Comments
I also got this issue |
Note that Playwright is only guaranteed to work with bundled browsers, so I expect some internal protocol mismatch. That said, if you could generate protocol logs for us, we would look into them for more details. For that, run with two environment variables and copy $ DEBUG=pw:protocol DEBUG_FILE=mylog.txt node myscript.js |
Here it is. |
Logs indicate there were no issues while handling the Did you try playwright v1.6? It roughly corresponds to Chromium 88.0.4316.0, so I expect things to work there. Overall, you can find out the version of bundled browsers in our (release notes)[https://github.com/microsoft/playwright/releases]. We usually expect similar version to work with Playwright, but older versions might break. |
Same issue here for me (
|
I had the same problem until I downgraded to Playwright |
I also have this with import { Browser, chromium, Page } from "playwright";
let browser: Browser;
let page: Page
before(async () => {
browser = await chromium.launch({ headless: false });
});
after(async () => {
await browser.close();
});
beforeEach(async () => {
page = await browser.newPage();
});
afterEach(async () => {
await page.close();
});
export { page, browser } |
+1 same issue with headful on v1.11.0. Process just hangs forever even with calling browser.close(); This should be considered a major bug that impacts all headful workflows imo. |
This is happening when I'm using the "chrome" stable channel (so it launches real Chrome), but I'm not seeing the issue with Chromium. |
Actually, I wasn't closing the browser properly, but it is still odd that the process hangs on chrome stable but not when "channel" is not specified when launching the browser. |
I also observed the same issue with Playwright 1.12.3, and Chrome 91.0.44.72.101 (32 bit).
|
I got the same problem on Playwright Python 1.15.2. The browser context |
I have the same issue with Playwright 1.19.2 (TypeScript), when I enable channel: "chrome", the tests are failing because browser.close() "hangs" and playwright is not able to start new browser for next test scenario. |
We are experiencing the same issues. Locally and within a Github Action. Node: 14.18.2 In Headless: False mode. I can see a browser not close and remain open until the suite complete and all closes as expected. In headless: True the workflow completes what it can per set workers/browsers, and then when all else is done, the workflow just sits there. In github, when I cancel to workflow/test, in the post clean up output I see something like this:
This is what leads me to believe this is also a firefox issue. |
I have the same issue with chromium. I am using:
The browser.close(); takes too long. |
Facing same issue. browser is not closing and test timesout. |
I have the same issue with chromium browser chrome channel (no issue for msedge). I am using:
await IBrowser.CloseAsync() takes 30 seconds and then times out. Attaching logs for pw:protocol and pw:browser |
This is still happening for all Chromium based browser macOS: My setup:
I'm running the following script:
|
@mohsen1 Enterprise policies may interfere with Playwright controlling the browser. We consider this case to be out of scope, so it's unlikely things will improve in this area. |
Thank you @dgozman, in a Mac without Chrome Enterprise the close times are around 2 seconds. It's surprising that Chrome Enterprise is impacting all of Chromium based browsers. I understand that this is outside of the scope of Playwright but do you have any suggestions where can I look for possible solutions? |
@mohsen1 There is no known workaround, except for using Playwright's built-in |
In our case, Chromium (without the |
@mohsen1 This is interesting. Could you please run with |
Updated the script to remove const { chromium, webkit, firefox } = require('@playwright/test');
async function main() {
const msedge = await chromium.launch({
channel: 'msedge',
headless: false,
});
console.log('\n\n*** MS Edge ***');
await test(msedge);
const chrome = await chromium.launch({
channel: 'chrome',
headless: false,
});
console.log('\n\n*** Chrome ***');
await test(chrome);
const chromiumBrowser = await chromium.launch({
headless: false,
});
console.log('\n\n*** Chromium ***');
await test(chromiumBrowser);
const webkitBrowser = await webkit.launch({
headless: false,
});
console.log('\n\n*** Webkit ***');
await test(webkitBrowser);
const firefoxBrowser = await firefox.launch({
headless: false,
});
console.log('\n\n*** Firefox ***');
await test(firefoxBrowser);
}
async function test(browser) {
const context = await browser.newContext();
const page = await context.newPage();
console.log(new Date().toLocaleTimeString(), 'Navigating to https://example.com');
await page.goto('https://example.com', { waitUntil: 'load' });
console.log(new Date().toLocaleTimeString(), 'Closing browser...');
console.time('Closing browser took');
await browser.close();
console.timeEnd('Closing browser took');
}
process.on('unhandledRejection', (reason, promise) => {
console.log('Unhandled Rejection at:', reason.stack || reason);
});
process.on('uncaughtException', (error) => {
console.log('Uncaught Exception thrown', error);
});
process.on('exit', (code) => {
console.log(new Date().toLocaleTimeString(), `About to exit with code: ${code}`);
});
main()
.then(() => {
console.log(new Date().toLocaleTimeString(), 'Script finished');
})
.catch((err) => {
console.error('Error during playwright script', err);
}); Command: Output:
I did not see any content in my |
I am not sure. After running your command on my computer, I got |
Something like: async function close(endpoint) {
let promise
const ws = new WebSocket(endpoint);
ws.on('open', function open() {
ws.send("{'id': 0, 'method': 'Browser.close', 'params':{}");
ws.close()
promise = Promise.resolve()
});
return await promise
}
const server = await chromium.launchServer({
headless: false,
executablePath: "C:/Program Files/Google/Chrome/Application/chrome.exe",
})
endpoint = server.wsEndpoint()
await close(endpoint) // patches https://github.com/microsoft/playwright/issues/5327 however raises the following after closing
( not sure how to catch that error) |
applies the close hook on a page to persist state of the context before quitting. doesn't work on chromium for now due to a known issue with how `browser.close()` doesn't work microsoft/playwright#5327
applies the close hook on a page to persist state of the context before quitting. doesn't work on chromium for now due to a known issue with how `browser.close()` doesn't work microsoft/playwright#5327
Context:
Code Snippet
Describe the bug
When running the test with no-headless Chrome (also happens with Chrome Dev, and Chrome Canary), the test is hung at
await browser.close()
and can not close the browser.The text was updated successfully, but these errors were encountered: