feat: Browser Use best practices — click/type/state improvements#707
Merged
feat: Browser Use best practices — click/type/state improvements#707
Conversation
- Add Critical Rules section (state over screenshot, verify with get value) - Add Command Cost Guide (free/instant vs expensive vision tokens) - Add Action Chaining Rules (safe to chain vs page-changing) - Add Tips section - Fix Core Workflow to use state/get value for verification, not screenshot - Mark screenshot as "ONLY for user deliverables" Inspired by Browser Use's design: DOM-first state representation, action cost awareness, and multi-action chaining patterns.
- Add rule: NEVER use eval to click/type — use click/type/select commands
(eval bypasses scrollIntoView + CDP pipeline, fails on off-screen elements)
- Add rule: eval is read-only, always wrap in IIFE to avoid variable conflicts
- Reorder Critical Rules for priority
- Add IIFE example in Extract section
Root cause: Claude Code was using eval("el.click()") instead of
click <index>, and hitting "already declared" errors from repeated
eval calls in the same page context.
Inspired by deep analysis of Browser Use's design patterns:
1. Framework listener detection (React/Vue/Angular)
- Detect __reactProps$ onClick, Vue _vei, Angular ng-reflect-click
- Catches <div onClick> elements that pure ARIA/tag heuristics miss
2. Click CDP fallback
- clickJs() now returns coordinates on failure
- BasePage.click() falls back to CDP Input.dispatchMouseEvent
- Page.clickWithQuads() uses DOM.getContentQuads for inline elements
3. Type improvements
- React-compatible: use native HTMLInputElement.prototype.value setter
- Contenteditable: selectAll + execCommand('insertText') for rich editors
- Autocomplete: detect role=combobox, wait 400ms for dropdown suggestions
4. getContentQuads precise click
- Page.clickWithQuads() for multi-line inline elements (e.g. wrapped <a>)
- Falls back through getContentQuads → getBoxModel → JS click
1. clickWithQuads: escape ref with JSON.stringify before inserting into JS strings and CSS selectors (injection risk) 2. base-page click: throw error when both JS click and CDP fallback fail instead of silently succeeding 3. typeTextJs: use matching prototype for native setter (HTMLTextAreaElement for textarea, HTMLInputElement for input)
just-buer
pushed a commit
to just-buer/opencli
that referenced
this pull request
Apr 8, 2026
…kwener#707) * docs: improve operate skill with Browser Use best practices - Add Critical Rules section (state over screenshot, verify with get value) - Add Command Cost Guide (free/instant vs expensive vision tokens) - Add Action Chaining Rules (safe to chain vs page-changing) - Add Tips section - Fix Core Workflow to use state/get value for verification, not screenshot - Mark screenshot as "ONLY for user deliverables" Inspired by Browser Use's design: DOM-first state representation, action cost awareness, and multi-action chaining patterns. * docs: fix operate skill — eval read-only, IIFE, interaction rules - Add rule: NEVER use eval to click/type — use click/type/select commands (eval bypasses scrollIntoView + CDP pipeline, fails on off-screen elements) - Add rule: eval is read-only, always wrap in IIFE to avoid variable conflicts - Reorder Critical Rules for priority - Add IIFE example in Extract section Root cause: Claude Code was using eval("el.click()") instead of click <index>, and hitting "already declared" errors from repeated eval calls in the same page context. * feat: Browser Use best practices — click/type/state improvements Inspired by deep analysis of Browser Use's design patterns: 1. Framework listener detection (React/Vue/Angular) - Detect __reactProps$ onClick, Vue _vei, Angular ng-reflect-click - Catches <div onClick> elements that pure ARIA/tag heuristics miss 2. Click CDP fallback - clickJs() now returns coordinates on failure - BasePage.click() falls back to CDP Input.dispatchMouseEvent - Page.clickWithQuads() uses DOM.getContentQuads for inline elements 3. Type improvements - React-compatible: use native HTMLInputElement.prototype.value setter - Contenteditable: selectAll + execCommand('insertText') for rich editors - Autocomplete: detect role=combobox, wait 400ms for dropdown suggestions 4. getContentQuads precise click - Page.clickWithQuads() for multi-line inline elements (e.g. wrapped <a>) - Falls back through getContentQuads → getBoxModel → JS click * fix: address code review — injection, silent failure, setter prototype 1. clickWithQuads: escape ref with JSON.stringify before inserting into JS strings and CSS selectors (injection risk) 2. base-page click: throw error when both JS click and CDP fallback fail instead of silently succeeding 3. typeTextJs: use matching prototype for native setter (HTMLTextAreaElement for textarea, HTMLInputElement for input)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Inspired by deep analysis of Browser Use, improve OpenCLI Operate's browser interaction layer:
__reactProps$onClick, Vue_vei, Angularng-reflect-clickinstateoutput, so<div onClick>elements get[N]indicesel.click()fails, automatically fall back to CDPInput.dispatchMouseEventwith coordinates; addclickWithQuads()usingDOM.getContentQuads/getBoxModelfor precise inline element clickingHTMLInputElement.prototype.value), contenteditable support viaexecCommand('insertText'), autocomplete/combobox field detection with 400ms waitFiles changed (6 files, +234/-54)
src/browser/dom-snapshot.tshasFrameworkListener()for React/Vue/Angularsrc/browser/dom-helpers.tsclickJs()returns coords;typeTextJs()native setter + contenteditablesrc/browser/base-page.tsclick()CDP fallback + error on both-failsrc/browser/page.tstryNativeClick(),clickWithQuads()src/cli.tstypecommandskills/opencli-operate/SKILL.mdTest plan
npm run buildpassesstateshows[N]on<div>buttons