Skip to content
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 hangs while waiting for pending navigations #33806

Closed
dgozman opened this issue Nov 28, 2024 · 3 comments · Fixed by #33834
Closed

[Bug]: playwright hangs while waiting for pending navigations #33806

dgozman opened this issue Nov 28, 2024 · 3 comments · Fixed by #33834
Assignees
Labels

Comments

@dgozman
Copy link
Contributor

dgozman commented Nov 28, 2024

Version

1.49.0

Steps to reproduce

Reported by @chrisbottin in #32899 (comment).

The problem we are having is when we click on a link which triggers the beforeunload dialog, after we dismiss the dialog and try to interact with the page again, we get timeout errors.

Here is a simple test replicating the error ...

const {chromium} = require('playwright');
const {expect} = require('@playwright/test');

(async () => {
    const browser = await chromium.launch();
    const page = await browser.newPage();

    await page.mainFrame().goto('https://www.npmjs.com/');

    expect(await page.mainFrame().title()).toStrictEqual('npm | Home');

    await page.evaluate(() => {
        window.onbeforeunload = () => false;
    });

    page.on('dialog', async dialog => {
        await dialog.dismiss();
    });

    await page.getByRole('menuitem', {name: 'Teams'}).click({noWaitAfter: true});

    await page.evaluate(() => {
        window.onbeforeunload = null;
    });

    // Timeout error will occur here:
    await page.getByRole('menuitem', {name: 'Teams'}).click({timeout: 1000});

    expect(await page.mainFrame().title()).toStrictEqual('npm | Teams');

    await browser.close();
})();

Expected behavior

Test passes.

Actual behavior

The test fails on the line await page.getByRole('menuitem', {name: 'Teams'}).click({timeout: 1000}); with the error:

locator.click: Timeout 1000ms exceeded.
Call log:
  - waiting for getByRole('menuitem', { name: 'Teams' })
  - waiting for navigation to finish...

Additional context

During debugging, I noticed the pendingDocument() is set to {documentId: undefined, request: undefined}

If this line

if (!mainFrame || !mainFrame.pendingDocument())
is changed to the following, our problem disappears:

if (!mainFrame || !mainFrame.pendingDocument() || !mainFrame.pendingDocument().documentId)
      return;

Environment

unknown
@dgozman
Copy link
Contributor Author

dgozman commented Nov 28, 2024

As a workaround, try running with PLAYWRIGHT_SKIP_NAVIGATION_CHECK=1 npx playwright test and let me know whether that helps.

@chrisbottin
Copy link

@dgozman Yes using PLAYWRIGHT_SKIP_NAVIGATION_CHECK environment variable works. This is the route we were going to take to be able to use 1.49 but we don't think it's a long-term solution.

@seahindeniz
Copy link

seahindeniz commented Nov 29, 2024

I'm not sure if it is related, but it doesn't work for me. Tried it on @playwright/[email protected]

PLAYWRIGHT_SKIP_NAVIGATION_CHECK=1 playwright test test.spec.ts --debug

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants