Skip to content

fix(playwright): replace constructor.name checks with stable public API (#5559)#5560

Merged
DavertMik merged 2 commits into
codeceptjs:4.xfrom
mirao:fix/playwright-160-within-see-5559
May 13, 2026
Merged

fix(playwright): replace constructor.name checks with stable public API (#5559)#5560
DavertMik merged 2 commits into
codeceptjs:4.xfrom
mirao:fix/playwright-160-within-see-5559

Conversation

@mirao
Copy link
Copy Markdown
Contributor

@mirao mirao commented May 13, 2026

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, so Locator silently became _Locator and FrameLocator likely _FrameLocator. This broke all constructor.name checks in Playwright.js.

Three fixes, all replacing fragile constructor.name checks with duck-typing on stable public-API methods:

Context type url() innerText() Correct branch
Page locator('body').innerText()
Frame locator('body').innerText()
FrameLocator locator('body').innerText()
Locator el.innerText()
  • proceedSee: el.constructor.name !== 'Locator'typeof el.url !== 'function' && typeof el.innerText === 'function' (the main bug — caused within() + I.see() to time out)
  • executeScript: constructor.name === 'FrameLocator'typeof el.url !== 'function' && typeof el.innerText !== 'function'
  • _getContext: (this.context && constructor.name === 'FrameLocator') || this.contextthis.context (the FrameLocator sub-check was logically redundant)

Test plan

  • Added a new unit test: within on css locator should use locator scope in see without explicit context — calls I.see() with no context arg while this.context is a Playwright Locator (the exact path that timed out)
  • Verified without the fix + Playwright 1.60: test fails with locator.innerText: Timeout exceeded — waiting for locator('#register').first().locator('body')
  • Verified with the fix + Playwright 1.60: 24/24 within tests pass
  • Verified with the fix + Playwright 1.59: 24/24 within tests pass (fully backward-compatible)

🤖 Generated with Claude Code

…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>
@mirao mirao changed the base branch from 3.x to 4.x May 13, 2026 08:50
@DavertMik
Copy link
Copy Markdown
Contributor

Thank you! Just foud failing tests on this!

@DavertMik DavertMik merged commit 743f603 into codeceptjs:4.x May 13, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Playwright 1.60: within() + I.see() times out — Locator renamed from 'Locator' to '_Locator'

2 participants