Skip to content

perf(ego-browser): stop re-validating snapshot stable locators - #813

Merged
joway merged 2 commits into
devfrom
zhuoweiwang/drop-snapshot-locator-check
Nov 26, 2026
Merged

joway merged 2 commits into
devfrom
zhuoweiwang/drop-snapshot-locator-check

Conversation

@joway

@joway joway commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Summary

page.snapshot() queried every stable locator the browser advertised again over CDP, and removed the ones that did not resolve to exactly their own node. The browser now does this check itself and prints a locator only when it matches exactly the node that produced it, so the SDK check repeated work and removed nothing.

This PR removes the SDK-side check. Locators are passed through as the browser advertises them.

Why

On pages with many locators the check cost more than the native snapshot. Measured on ego lite 0.6.4.20, median of 7 runs, with the check on and off in the same process:

Page Scope Locators With check Without Saved
Hacker News viewport 140 65 ms 8 ms 87%
Hacker News full page 193 83 ms 9 ms 89%
GitHub repo page viewport 65 72 ms 34 ms 52%
GitHub repo page full page 244 150 ms 38 ms 75%
Wikipedia article full page 1637 11730 ms 2976 ms 75%
Page with 4 iframes viewport 4 26 ms 23 ms 11%

Across these pages the check removed none of about 2,300 advertised locators.

What changed

  • preparePageSnapshotResult no longer validates locators. validateSnapshotLocator, sanitizeSnapshotLocators and their two text-rewriting helpers are removed.
  • Kept: backfilling a missing frameId for refs inside iframes, which still uses validateLocatorBackendNodes, and omitting the loc=unstable / loc=ambiguous sentinels that earlier browsers print.
  • Unit tests: the case for hiding invalid locators is replaced by one that checks locators pass through with no CDP calls. The cases that exercised the validator through the removed wrapper now call validateLocatorBackendNodes directly.
  • E2E: the Page snapshot locator quality case required two links sharing an href to carry no locator at all. The current browser gives each of them a unique role:link[name="…"] locator, so the case failed with or without this change. It now rejects only the shared href: locator and resolves the other locator to confirm it matches one element.
  • docs/native-snapshot-ref-requirement.md no longer says the JS runtime validates locators.

Reviewer notes

  • Older browsers: with a browser that predates the native check, inaccurate locators are no longer filtered by the SDK.
  • Not addressed here: the native snapshot with stable locators took about 3 s on the Wikipedia article, against 20–30 ms with includeStableLocator: false. That time is spent in the browser and is unchanged by this PR.
  • The measurements cover five sites, one with iframes; pages with heavy shadow DOM were not measured.

Tests

  • npm test: 712 pass.
  • npm run e2e (pre-push hook): passes on ego lite 0.6.4.20.

🤖 Generated with Claude Code

joway and others added 2 commits November 26, 2026 13:11
page.snapshot() queried every advertised locator again over CDP and
dropped the ones that did not resolve uniquely to their own node. The
browser now prints a locator only when it matches exactly that node, so
the check removed nothing and cost more than the native snapshot on
pages with many locators (GitHub repo page, full page: 150 ms -> 24 ms).

Locators are passed through as advertised. Backfilling a missing
frameId for iframe refs still uses validateLocatorBackendNodes, and the
loc=unstable / loc=ambiguous sentinels of earlier browsers are still
omitted. With a browser that predates the native check, inaccurate
locators are no longer filtered by the SDK.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…n href

A browser that verifies locators gives each of two links with the same
href its own role-and-name locator. The case required those links to
carry no locator at all, so it failed on such a browser with or without
the SDK-side check. It now rejects only the shared href locator and
resolves the other locator to confirm it matches one element.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

🤖 Codex Review · 734b4a1b

2026-11-26 05:20 UTC · generated automatically by openai/codex-action

No issues found that require changes.

@joway
joway merged commit a799259 into dev Nov 26, 2026
3 checks passed
@joway
joway deleted the zhuoweiwang/drop-snapshot-locator-check branch November 26, 2026 05:24
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.

1 participant