Skip to content

[Bug]: ariaSnapshot({ mode: 'ai' }) omits iframe contents when the <iframe> element has fallback text #43628

Closed

Description

Version

playwright-core 1.64.1 (also the 1.64.0-alpha bundled with @playwright/mcp 0.0.83). Chromium headless shell 1248, Windows 11.

Bug

page.ariaSnapshot({ mode: 'ai' }) (the snapshot @playwright/mcp returns) omits the whole contents of a same-origin iframe whenever the <iframe> element has text between its tags (fallback content). The child frame is captured, but the output only shows the fallback text.

Repro

child.html

<!doctype html><title>child</title><h1>Child heading</h1><p>Intro text in frame</p>
<form><label>One <input name=one></label><button type=button>Eggs, Sausages</button></form>

plain.html

<!doctype html><title>plain</title><h1>Outer</h1><iframe src="child.html" title="plain-frame"></iframe>

fallback.html (same, but with text inside the iframe element)

<!doctype html><title>fallback</title><h1>Outer</h1><iframe src="child.html" title="fallback-frame">Your browser does not support frames</iframe>
const { chromium } = require('playwright-core');
(async () => {
  const b = await chromium.launch(); const p = await b.newPage();
  for (const f of ['plain', 'fallback']) {
    await p.goto(require('url').pathToFileURL(require('path').join(__dirname, f + '.html')).href);
    console.log('== ' + f + ' ==\n' + await p.ariaSnapshot({ mode: 'ai' }));
  }
  await b.close();
})();

Actual

== plain ==
- generic [active] [ref=e1]:
  - heading "Outer" [level=1] [ref=e2]
  - iframe [ref=e3]:
    - generic [ref=f1e1]:
      - heading "Child heading" [level=1] [ref=f1e2]
      - paragraph [ref=f1e3]: Intro text in frame
      - generic [ref=f1e4]:
        - generic [ref=f1e5]:
          - text: One
          - textbox "One" [ref=f1e6]
        - button "Eggs, Sausages" [ref=f1e7]
== fallback ==
- generic [active] [ref=f2e1]:
  - heading "Outer" [level=1] [ref=f2e2]
  - iframe [ref=f2e3]: Your browser does not support frames

Expected

The fallback snapshot lists the child frame's heading, paragraph, textbox and button like plain does. Fallback text is only used by browsers that can't render frames, so it should not replace content that was successfully captured.

Likely cause

In the iframe merge step (mergeIframeChildren in the bundled core) the captured child snapshot is assigned with node.children = childSnapshot but the iframe node's existing text (the fallback text) is left in place. The YAML renderer prefers node.text over node.children (if (node.text !== undefined) visitText(...) else for (const child of node.children ...)), so the children are never printed. Clearing node.text when childSnapshot?.length is truthy (and keeping it when the frame is genuinely unavailable) should fix it.

Impact

Pages that put fallback text inside <iframe> (common on older/legacy pages and some test sites) look like they have an empty frame to agents using @playwright/mcp: no content, no refs for the controls inside, and no hint that the frame loaded. Seen in a browser-agent benchmark where agents given the tree snapshot could not read or interact with the frame form.

Activity

  1. github-actions commented on Oct 25, 2026

    @github-actions
    Contributor

    Hi, I'm the Playwright bot and I investigated this.

    Reproduced on Linux in Chromium, Firefox and WebKit, using 1.65.0-next at 91a765d1681cb3eeb0d0fb89fefec3cf0d21bd9b. The iframe merge keeps fallback text alongside the captured children, and the renderer chooses that text instead of the child tree. The proposed fix clears the text when a child snapshot is attached.

    Reproduction and verification

    I extended the existing frame-stitching test: capture the nested-frame snapshot, add fallback text to the loaded iframe elements, then check that the snapshot stays unchanged:

    const snapshot = await page.ariaSnapshot({ mode: 'ai' });
    await page.locator('iframe').evaluateAll(iframes => {
      for (const iframe of iframes)
        iframe.textContent = 'Your browser does not support frames';
    });
    expect(await page.ariaSnapshot({ mode: 'ai' })).toBe(snapshot);

    The final assertion fails without the fix in all three browsers, with fallback text replacing the child trees. It passes with the fix. All 318 tests in page-aria-snapshot-ai.spec.ts, page-aria-snapshot-json.spec.ts and page-aria-snapshot.spec.ts pass, as do the build and full lint/type checks.

    I also tested #43633 at 6e8f9e1b29ff35782cc25f7678648c9650b484c4: both this regression and its added regression test pass in all three browsers.

    Tests used headless browsers on Linux. Windows and the reported published versions were not tested.

    Draft fix: #43635

    Triaged on Linux by the Playwright bot - agent run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions