fix(playwright): replace constructor.name checks with stable public API (#5559)#5560
Merged
DavertMik merged 2 commits intoMay 13, 2026
Merged
Conversation
…PI (codeceptjs#5559) Playwright 1.60 switched to an esbuild bundle which silently renames internal classes (e.g. Locator → _Locator), breaking all constructor.name checks. Replace them with duck-typing on stable public-API methods: Page/Frame expose url(), Locator exposes innerText(), FrameLocator exposes neither. Also adds a regression test that calls I.see() without an explicit context inside a CSS within() block — the exact path that timed out. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
|
Thank you! Just foud failing tests on this! |
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.
Summary
Fixes #5559.
Playwright 1.60 switched its distribution from individual compiled files to a single esbuild bundle. esbuild prefixes class names with
_to avoid naming conflicts, soLocatorsilently became_LocatorandFrameLocatorlikely_FrameLocator. This broke allconstructor.namechecks inPlaywright.js.Three fixes, all replacing fragile
constructor.namechecks with duck-typing on stable public-API methods:url()innerText()Pagelocator('body').innerText()Framelocator('body').innerText()FrameLocatorlocator('body').innerText()Locatorel.innerText()proceedSee:el.constructor.name !== 'Locator'→typeof el.url !== 'function' && typeof el.innerText === 'function'(the main bug — causedwithin()+I.see()to time out)executeScript:constructor.name === 'FrameLocator'→typeof el.url !== 'function' && typeof el.innerText !== 'function'_getContext:(this.context && constructor.name === 'FrameLocator') || this.context→this.context(the FrameLocator sub-check was logically redundant)Test plan
within on css locator should use locator scope in see without explicit context— callsI.see()with no context arg whilethis.contextis a PlaywrightLocator(the exact path that timed out)locator.innerText: Timeout exceeded — waiting for locator('#register').first().locator('body')🤖 Generated with Claude Code