fix(web): elements inside a hidden iframe read as hidden

Merged
OK
13d ago
+189-40
  • The web engine now reads each frameLocator hop's iframe element in the document around it, in frameOf (packages/web/src/surface.ts), using the e2e-shown engine that is already registered. If the iframe is hidden, every node inside it is hidden too, and so is every frame nested under it. This is how Playwright's _queryFrames carries frameVisible.
  • The read happens in the parent document, so cross-origin frames work. It costs one count per hop, skipped once an outer frame is already hidden.
  • In a hidden frame, isVisible(), toBeVisible/toBeHidden, waitFor and actionability waits all see states.hidden: true. Observation already left hidden iframes out (read-semantics.ts), so it agrees.
  • A { visible: true } or role query inside a hidden frame matches nothing, under an index or scope too, as the engine contract requires ("a role query never matches a node whose states.hidden is true"). This differs from Playwright: its getByRole and visible=true filter are per document and still match there.
  • Removed 3 fail marks in apps/testbed/tests/locator-frame.e2e.ts:
    • should treat elements inside hidden iframe as hidden
    • should treat elements inside hidden cross-origin iframe as hidden
    • should wait for hidden iframe to become visible
await expect(browser.frameLocator('[name=hidden]').locator('button')).toBeHidden();
expect(await browser.frameLocator('iframe').locator('div').isVisible()).toBe(false); // cross-origin

Verified

Ran it locally: yes

  • Testbed, node node_modules/e2e/dist/cli/bin.js run --tag playwright, on another port because a parallel checkout held 4271: 503 passed, 6 skipped. On main the 3 tests carried fail marks and failed.
  • Full testbed suite: 579 passed, 7 skipped.
  • Web benchmark: 91/91.
  • New integration test packages/web/tests/integration/hidden-frames.test.ts covers:
    • a hidden frame
    • a frame under a hidden ancestor
    • a nested chain
    • an iframe with visibility: visible under a hidden ancestor
    • visible and role queries
    • a frame that shows again
  • Known flake, not from this PR: should wait for frame to go failed 2 of 15 runs on main as well (a boundingBox wait race when the frame is removed mid-locate).