fix(web): elements inside a hidden iframe read as hidden
Merged
OK
13d ago+189+189+012345678901234567890123456789-40-40-01234567890123456789
- The web engine now reads each
frameLocatorhop's iframe element in the document around it, inframeOf(packages/web/src/surface.ts), using thee2e-shownengine 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_queryFramescarriesframeVisible. - The read happens in the parent document, so cross-origin frames work. It costs one
countper hop, skipped once an outer frame is already hidden. - In a hidden frame,
isVisible(),toBeVisible/toBeHidden,waitForand actionability waits all seestates.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 whosestates.hiddenis true"). This differs from Playwright: itsgetByRoleandvisible=truefilter are per document and still match there. - Removed 3
failmarks inapps/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 carriedfailmarks and failed. - Full testbed suite: 579 passed, 7 skipped.
- Web benchmark: 91/91.
- New integration test
packages/web/tests/integration/hidden-frames.test.tscovers:- a hidden frame
- a frame under a hidden ancestor
- a nested chain
- an iframe with
visibility: visibleunder a hidden ancestor - visible and role queries
- a frame that shows again
- Known flake, not from this PR:
should wait for frame to gofailed 2 of 15 runs on main as well (aboundingBoxwait race when the frame is removed mid-locate).