playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Bug] Firefox: `frameCommittedNewDocumentNavigation` throws on an unknown frame and kills the driver

Open 00al opened this issue 1 week ago • 2 comments

Version 1.58.0 (still on main). In server/frames.ts, every other frame handler ignores a frame id it doesn't know (frameAttached path, frameCommittedSameDocumentNavigation, frameAbortedNavigation, frameDetached, frameLifecycleEvent), but frameCommittedNewDocumentNavigation does this._frames.get(frameId)! and then removeChildFramesRecursively(frame), which throws TypeError: Cannot read properties of undefined (reading 'childFrames') and exits the Node driver.

Seen on Firefox (Juggler) when a page with a solved reCAPTCHA iframe redirects twice within ~1.5 s: a late Page.navigationCommitted arrives for an already-detached frame.

Minimal check: call the method with an unknown frame id on a FrameManager whose _frames is empty; it throws.

Suggested fix: if (!frame) return; as in the sibling handlers.

Related: #18415, #35570.

00al avatar Nov 18 '26 12:11 00al

Hi, I'm the Playwright bot. I started triaging this issue on Linux: agent run

Hi, I'm the Playwright bot. I could not reproduce the browser crash on 1.58.0 or main (d456688ec2c9fbcbc4a8515afb901fabdcf1a136) on Linux.

I tested a cross-origin iframe navigating while its parent redirects twice, with a nested iframe also loading. All three browsers passed, headless and headed. Calling the internal method with a fabricated frame ID does throw the reported error, but this does not establish how Firefox produces that event order. I could not verify the reCAPTCHA-specific trigger from the information in the report.

I propose coverage by extending the existing frame-detachment test. Production code is unchanged, and this does not close the issue.

Scenario tested

Using the repository's page and server fixtures:

for (const [path, next] of [
  ['/redirect1.html', '/redirect2.html'],
  ['/redirect2.html', '/empty.html'],
]) {
  server.setRoute(path, (req, res) => {
    res.writeHead(200, { 'Content-Type': 'text/html' });
    res.end(`
      <script>
        addEventListener('message', () => location.href = ${JSON.stringify(server.PREFIX + next)}, { once: true });
      </script>
      <iframe src="${server.CROSS_PROCESS_PREFIX}/navigating-child.html"></iframe>
    `);
  });
}
server.setRoute('/navigating-child.html', (req, res) => {
  res.writeHead(200, { 'Content-Type': 'text/html' });
  res.end(`
    <iframe src="/frames/frame.html"></iframe>
    <script>
      parent.postMessage('redirect', '*');
      location.href = '/frames/two-frames.html';
    </script>
  `);
});
await page.goto(server.PREFIX + '/redirect1.html', { waitUntil: 'commit' });
await page.waitForURL(server.EMPTY_PAGE);
expect(page.frames()).toEqual([page.mainFrame()]);
await expect(page.locator('iframe')).toHaveCount(0);
Checks and related findings

Each browser passed 50 redirect cycles in each mode, headless and headed under Xvfb:

Playwright Chromium Firefox WebKit
1.58.0 145.0.7632.6 146.0.1 26.0
main, d456688ec2c9fbcbc4a8515afb901fabdcf1a136 159.0.8154.6 159.0 27.2

The main runs used the test-server fixtures. The 1.58.0 runs used equivalent pages served through page.route() with the matching 1.58.0 runner.

The final change and neighboring frame-navigation tests passed on all three browsers: 49 passed, 2 existing skips. The extended test also passed headed on all three. npm run build and npm run flint passed.

The same guard was proposed in #10494 and declined because it concealed the underlying frame-ordering problem. #18415 was addressed by the Firefox update in #20271; #35570 was closed without a runnable reproduction. None establishes a fix for this report.

Draft PR: https://github.com/microsoft/playwright/pull/44213

Triaged on Linux by the Playwright bot - agent run