fix(mcp): anchor aria-ref regex in target resolution (#40610)

This commit is contained in:
Yury Semikhatsky
2026-05-04 12:47:16 -07:00
committed by GitHub
parent 0435faef1a
commit 7579e1b34c
3 changed files with 25 additions and 1 deletions
+2
View File
@@ -139,6 +139,8 @@ Never add "Generated with" in commit message.
Never add test plan to PR description. Keep PR description short — a few bullet points at most.
Branch naming for issue fixes: `fix-<issue-number>`
**Never amend commits.** Always create a new commit for follow-up changes, even when iterating on an open PR. Amending rewrites history and forces a force-push, losing the incremental review trail. Only amend if the user explicitly says so.
**Never `git push` without an explicit instruction to push.** Applies even when a PR is already open for the branch — additional commits are immediately visible to reviewers. Commit locally, report what was committed, and wait. Only push when the user's message contains "push", "upload", "create PR", "ship it", or equivalent.
## Development Guides
@@ -444,7 +444,7 @@ export class Tab extends EventEmitter<TabEventsInterface> {
async targetLocators(params: { element?: string, target: string }[]): Promise<{ locator: playwright.Locator, resolved: string }[]> {
await this._initializedPromise;
return Promise.all(params.map(async param => {
if (!param.target.match(/(f\d+)?(e\d+)/)) {
if (!param.target.match(/^(f\d+)?e\d+$/)) {
const selector = locatorOrSelectorAsSelector('javascript', param.target, this.context.config.testIdAttribute || 'data-testid');
const handle = await this.page.$(selector);
if (!handle)
+22
View File
@@ -202,3 +202,25 @@ test('browser_click (test id attribute)', async ({ startClient, server, mcpBrows
code: `await page.getByTestId('submit').click();`,
});
});
test('browser_click (locator target containing aria-ref-like substring)', async ({ client, server }) => {
server.setContent('/', `
<title>Title</title>
<button id="z2l9e43l3">Submit</button>
`, 'text/html');
await client.callTool({
name: 'browser_navigate',
arguments: { url: server.PREFIX },
});
expect(await client.callTool({
name: 'browser_click',
arguments: {
element: 'Submit button',
target: '#z2l9e43l3',
},
})).toHaveResponse({
code: `await page.locator('#z2l9e43l3').click();`,
});
});