Skip to content

feat(cli): add pick and highlight commands#40213

Merged
pavelfeldman merged 1 commit intomicrosoft:mainfrom
pavelfeldman:pick_highlight
Apr 14, 2026
Merged

feat(cli): add pick and highlight commands#40213
pavelfeldman merged 1 commit intomicrosoft:mainfrom
pavelfeldman:pick_highlight

Conversation

@pavelfeldman
Copy link
Copy Markdown
Member

Summary

  • adds playwright-cli pick / browser_pick_locator — prompts the user to click an element in the browser and prints its ref and generated locator
  • adds playwright-cli highlight <el> (and --hide) / browser_highlight + browser_hide_highlight — persistent, stackable element highlight overlays
  • adds Locator.ariaRef() (JS-only) returning the aria ref of the matched element
  • Highlight now tracks multiple selectors via addElementHighlight/removeElementHighlight, replacing single-selector runHighlightOnRaf

Both commands live under the devtools capability.

Adds two new CLI/MCP commands backed by the devtools capability:

- `pick` / `browser_pick_locator` — waits for the user to click an element
  in the browser, prints its `ref` and generated locator.
- `highlight <el>` / `browser_highlight` + `--hide` / `browser_hide_highlight` —
  adds a persistent highlight overlay for an element and removes it on demand.

Supporting changes:

- New `Locator.ariaRef()` API (JS-only, internal protocol method) returning
  the aria ref assigned by the most recent aria snapshot.
- `Highlight.addElementHighlight`/`removeElementHighlight` replace the
  single-selector `runHighlightOnRaf`, tracking multiple selectors so several
  highlights can coexist until individually removed.
- `InjectedScript.addHighlight`/`removeHighlight` wired to the new methods.
if no ref has been assigned yet. Call [`method: Locator.ariaSnapshot`] or [`method: Page.ariaSnapshot`] before this
method to ensure a ref is available.

### option: Locator.ariaRef.timeout = %%-input-timeout-%%
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually need it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't, but since locator is getting resolved it is there, it needs to be guarded.


const highlight = declareCommand({
name: 'highlight',
description: 'Show (or with --hide, remove) a highlight overlay for an element',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also add hide all in some form.

@github-actions
Copy link
Copy Markdown
Contributor

Test results for "MCP"

6 failed
❌ [chrome] › mcp/dashboard.spec.ts:48 › should show current workspace sessions first @mcp-windows-latest
❌ [firefox] › mcp/http.spec.ts:103 › http transport browser lifecycle (isolated) @mcp-windows-latest
❌ [firefox] › mcp/init-script.spec.ts:22 › --init-script option loads and executes script (isolated) @mcp-windows-latest
❌ [firefox] › mcp/launch.spec.ts:101 › isolated context @mcp-windows-latest
❌ [webkit] › mcp/dashboard.spec.ts:48 › should show current workspace sessions first @mcp-windows-latest
❌ [msedge] › mcp/dashboard.spec.ts:26 › should show browser session chip @mcp-windows-latest

6010 passed, 952 skipped


Merge workflow run.

@github-actions
Copy link
Copy Markdown
Contributor

Test results for "tests 1"

2 flaky ⚠️ [chromium-library] › library/video.spec.ts:275 › screencast › should capture navigation `@chromium-ubuntu-22.04-arm-node20`
⚠️ [firefox-page] › page/page-emulate-media.spec.ts:144 › should keep reduced motion and color emulation after reload `@firefox-ubuntu-22.04-node20`

39148 passed, 847 skipped


Merge workflow run.

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.

2 participants