Closed trotzig closed 1 year ago
I can reproduce it, after the dialog is dismissed await page.evaluate(() => window.location.reload());
is still hanging, the dialog seems to stay open too.
Running into this issue as well. In my case await page.goBack()
hangs forever if an onbeforeunload
dialog is shown, even if I add an on('dialog')
listener that dismisses it (dialog is not dismissed when I run in headless: false
mode).
@trotzig , @yury-s , was this working for either of you in a prior version of Playwright? I'd be happy to downgrade if it is. I tried installing some older versions yesterday but didn't have any luck.
I know this was working in Puppeteer (we noticed it when porting to Playwright).
I don't know. I know it worked at some point in Puppeteer but I have no details really.
Fortunately it does work in Firefox on Playwright. Using that for now.
I experience the same bug. In my case, I'm testing a Chrome Extension, and so the website I enter has this before-leaving-are-you-sure dialog.
Because both the dialog.dismiss()
and the dialog.accept()
functions didn't work, I decided to avoid this dialog by overriding the onbeforeunload
event that caused it:
await page.evaluate(() => {
window.onbeforeunload = null;
})
I'm also seeing this issue - in my case, I'm injecting a beforeUnload handler to deliberately block navigation away and as such, need to dismiss the beforeunload dialog to block the navigation
I'm also facing this issue. I'm experimenting with some monkey testing with Gremilins.js and I'm trying to inject beforeunload to prevent navigation outside the current page.
Merging this into https://github.com/microsoft/playwright/issues/21715
Context:
Code Snippet
Describe the bug
We use Playwright at happo.io to take screenshots of web components/pages. One of our integration types is a Storybook runner that turns your Storybook stories into Happo screenshot tests. We iterate over all stories and render them one by one, taking a screenshot for each story. In rare cases, the Storybook story can trigger a navigation/change of location. This is bad for our test runner, so we try to disable them by adding a
beforeunload
listener and apage.on('dialog', ...)
handler to auto-dismiss the dialog that appears when the page context is about to change/unload.For some reason, calling
dialog.dismiss()
on the dialog that is triggered by abeforeunload
event doesn't seem to dismiss the dialog. There's no error, and execution continues, but any communication with the Playwright page/context (e.g. callingpage.evaluate
) will stall.The above code snippet will reproduce the bug. You'll see these terminal logs:
and nothing more. The expected output would be:
If you run the script in headful mode, you'll see that the "Reload site?" dialog remains visible even though the
dialog.dismiss()
call succeeds.I can reproduce the bug using the repro script in Chrome and Webkit.