playwright
playwright copied to clipboard
[BUG] before unload dialog is not closed after accept or dismiss
System info
- Playwright Version: [v1.31.2]
- Operating System: [macOS 13.2.1]
- Browser: [Chromium]
- Other info: [Node 16.16.0]
Source code
- [x] I provided exact source code that allows reproducing the issue locally.
Test file (self-contained)
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch({
devtools: true
});
const context = await browser.newContext();
const page = await context.newPage();
await page.goto('https://example.com');
page.on('dialog', async dialog => {
console.log(`Found dialog. Type: ${dialog.type()}, message: ${dialog.message()}`); // get dialog type and message
// await dialog.dismiss(); // Does not close the dialog and does not navigate
await dialog.accept(); // Does not close the dialog but allows the navigation
})
await page.addScriptTag({ content: 'window.onbeforeunload = (evt) => { evt.preventDefault(); evt.returnValue = ""}' })
await page.locator('body').click(); // chromium requires a user gesture to enable beforeunload
await page.evaluate('window.location="https://www.iana.org/domains/reserved"')
await page.waitForTimeout(3000) // wait to check if the dialog disappears
await context.close();
await browser.close();
})();
Steps
- [Run the script]
Expected
If the dialog is dismissed, the dialog should close and the navigation should fail and the browser closes If the dialog is accepted, the dialog should close and the navigation should occur and the browser closes
Actual
If the dialog is dismissed, the dialog does NOT close. The navigation does not occur and the browser does NOT close If the dialog is accepted, the dialog does NOT close, although the navigation does occur and the browser does close
Note: https://github.com/microsoft/playwright/issues/14431 is similar, but only covers dismiss. I'm also seeing the issue with accept
@kspeers-r7 Thank you, I can repro.
This is MacOS-specific. Filed upstream issue: https://bugs.chromium.org/p/chromium/issues/detail?id=1429458.
Looks like the upstream issue got resolved. Will it be updated in Playwright?
Yes, its currently blocked by https://github.com/microsoft/playwright/issues/22967 which is blocking the 1.34 release.
and #22967 is closed now
The dialog now disappears.
The page.evaluate
call that changes location
, in case of beforeunload
handler that is dismissed, never resolves though.
Filed this separately: https://github.com/microsoft/playwright/issues/23141