Skip to content

Make browser state refs read-only - #2295

Draft
ruohuaqian wants to merge 1 commit into
jackwener:mainfrom
ruohuaqian:agent/read-only-browser-state
Draft

Make browser state refs read-only#2295
ruohuaqian wants to merge 1 commit into
jackwener:mainfrom
ruohuaqian:agent/read-only-browser-state

Conversation

@ruohuaqian

Copy link
Copy Markdown

Summary

Make normal browser state snapshots read-only for page DOM.

browser state still emits stable [N] refs, but stores the live element map in window.__opencli_ref_elements instead of writing data-opencli-ref attributes onto business DOM nodes. The target resolver now prefers that in-memory map and keeps legacy data-opencli-ref lookup as a compatibility fallback.

Annotated screenshots still opt into DOM annotation because the visual overlay currently relies on those attributes.

Root Cause

Some sites monitor unexpected DOM attribute mutations. The previous DOM snapshot path wrote data-opencli-ref attributes during ordinary state reads, which could trigger page-side integrity logic and cause repeated refreshes or redirects.

Validation

  • npx vitest run --project unit src/browser/dom-snapshot.test.ts src/browser/target-resolver.test.ts src/browser/base-page.test.ts
  • npm run typecheck
  • npm run build
  • Manual smoke test on https://www.zhipin.com/web/geek/jobs: opencli browser zhipinfix state returned the page state, and document.querySelectorAll('[data-opencli-ref]').length returned 0 after the state read.

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