[Bug]: locator.toString() and call logs render regexes with u/s/y/d/v flags as string literals
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 74/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
- Domain
- testing-qa
Research direction
Start in packages/isomorphic/locatorGenerators.ts at detectExact and reproduce the issue with the locator examples in the report. Check the rendered locator, timeout call log, trace viewer, UI mode, HTML report, and codegen output; done means regexes with u/s/y/d/v flags remain regex literals while matching behavior stays unchanged.
Written by the indexing model from the issue text.
Description
Version
1.64.0-next (main @ 07f1a6154); long-standing
Steps to reproduce
import { test } from '@playwright/test';
test('locator description with regex flags', async ({ page }) => {
console.log(page.getByText(/foo/u).toString());
console.log(page.getByText(/foo/s).toString());
console.log(page.getByText(/foo/i).toString());
console.log(page.getByLabel(/foo/u).toString());
console.log(page.locator('div').filter({ hasText: /foo/u }).toString());
});
Expected behavior
getByText(/foo/u)
getByText(/foo/s)
getByText(/foo/i)
getByLabel(/foo/u)
locator('div').filter({ hasText: /foo/u })
Actual behavior
getByText('/foo/u')
getByText('/foo/s')
getByText(/foo/i)
getByLabel('/foo/u')
locator('div').filter({ hasText: '/foo/u' })
Matching itself is correct; only the rendered locator is wrong. The same string shows up in timeout call logs (waiting for getByText('/nope/u')), the trace viewer and UI mode "pick locator", the HTML report, and codegen output. Pasting the shown locator back into a test matches the literal text /foo/u instead of the regex.
Additional context
detectExact in packages/isomorphic/locatorGenerators.ts recognises a regex with /^\/(.*)\/([igm]*)$/, while the selector parser accepts [dgimsuvy] and escapeRegexForSelector emits whatever flags the user wrote. For internal:text=/foo/u the match fails, so the body falls through and is quoted as a string. internal:role and internal:attr go through parseAttributeSelector and are unaffected.
The u flag is common with non-ASCII patterns, and s with multi-line text.
I intend to work on this and will send a PR.
Environment
- Operating System: macOS (Darwin 25.6.0)
- Node.js: 24.8.0
- Browser: Chromium (bundled r1246)
- Playwright: main @ 07f1a6154
- Dominant language
- TypeScript
- Stars
- 96.4k
- Forks
- 6.5k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 170
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/playwright
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
microsoft/playwright#42804 ·
-
[CLI]: skill doesn't warn that a generated locator is only unique against the current page state Openneeds-triage-mac
Difficulty 1/5 Under an hour Newbie friendliness 91/100
microsoft/playwright#42790 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
microsoft/playwright#42782 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
microsoft/playwright#42745 · 1 comment ·
-
[Bug]: MCP idle timeout closes the browser during a tool call that outlasts it, failing that call Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
microsoft/playwright#42693 · 1 comment ·
All issues in microsoft/playwright
Similar issues
-
comp/dashboard P3 type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
NousResearch/hermes-agent#117722 ·
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 76/100
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·