fix(Playwright): switchTo resolves nested iframes relative to current frame - #5717
Open
DavertMik wants to merge 1 commit into
Open
fix(Playwright): switchTo resolves nested iframes relative to current frame#5717DavertMik wants to merge 1 commit into
DavertMik wants to merge 1 commit into
Conversation
… frame switchTo() always built the frame locator from the page, so switching into an iframe nested inside the current frame silently resolved to nothing: the step passed, but every following action timed out and no element on any level was reachable. The existence check ahead of it runs against the current frame, which is why the bad switch was never reported. Chain the frame locator from the current frame when there is one, as 3.x did. frameLocator() is synchronous, so the Promise.race wrapper never raced anything and left a dangling 5s timer behind on every switchTo call. Fixes #5688 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M93h8jjpyUt1A7Px3kwpxC
DavertMik
force-pushed
the
fix/playwright-nested-switchto-5688
branch
from
September 13, 2026 22:31
ff337cf to
54dd76d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5688
Problem
On Playwright, switching into an iframe that is nested inside the current frame left the helper pointing at nothing:
After the second
switchTonothing was reachable any more — not the nested frame, not the parent frame, not the top level. Puppeteer and WebDriver were unaffected, andwithin({ frame: [...] })worked, which is why this read as a Playwright-only regression.Cause
switchTo()built the frame locator fromthis.pageunconditionally:So
'[name=content]'was looked up on the top-level document, where it does not exist, and the resultingFrameLocatorresolved to nothing.The failure was silent because the existence check immediately above it goes through
_locateElement(), which does honour the current frame. The frame was found, then discarded.Introduced in cb7efd6 (while removing TestCafe); 3.x chained the locator correctly.
Fix
Chain from the current frame when there is one, as 3.x did:
The
Promise.racewrapper goes away with it:frameLocator()is synchronous, so it never raced anything and left an uncleared 5s timer behind on everyswitchTocall.Tests
Three cases added to the shared web API spec, since the behaviour is cross-helper:
4.xswitchTo(null)returning to the top level from a nested frame — fails on4.xswitchToresolves the frame against the current context rather than the page (passes either way; guards the fix from being "fixed" by widening the lookup to the whole document)Verified locally against Playwright and Puppeteer (
#switchTo, plus the fullwithin/iframe/frame set inPlaywright_test.js— 43 passing) and against the acceptancewithinsuite (8 passing). WebDriver runs in CI.🤖 Generated with Claude Code
https://claude.ai/code/session_01M93h8jjpyUt1A7Px3kwpxC