playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[BUG] before unload dialog is not closed after accept or dismiss

Open kspeers-r7 opened this issue 1 year ago • 6 comments

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

kspeers-r7 avatar Mar 16 '23 15:03 kspeers-r7

Note: https://github.com/microsoft/playwright/issues/14431 is similar, but only covers dismiss. I'm also seeing the issue with accept

kspeers-r7 avatar Mar 16 '23 15:03 kspeers-r7

@kspeers-r7 Thank you, I can repro.

dgozman avatar Mar 16 '23 19:03 dgozman

This is MacOS-specific. Filed upstream issue: https://bugs.chromium.org/p/chromium/issues/detail?id=1429458.

dgozman avatar Mar 31 '23 02:03 dgozman

Looks like the upstream issue got resolved. Will it be updated in Playwright?

dariatrainor avatar May 08 '23 01:05 dariatrainor

Yes, its currently blocked by https://github.com/microsoft/playwright/issues/22967 which is blocking the 1.34 release.

mxschmitt avatar May 16 '23 10:05 mxschmitt

and #22967 is closed now

dimkin-eu avatar May 18 '23 09:05 dimkin-eu

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

aslushnikov avatar May 18 '23 18:05 aslushnikov