From f714c7920b9a494b7eac7754ebc2596a96e3733d Mon Sep 17 00:00:00 2001 From: leeguooooo Date: Wed, 17 Jun 2026 01:15:31 +0900 Subject: [PATCH] fix(eval): replMode so successive evals can re-declare let/const; snapshot-first skill rule (#37, #38) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #38: `chrome-use eval` now runs with Runtime.evaluate replMode (like the DevTools console) — top-level `let`/`const` no longer throw "already been declared" across successive evals (independent `eval` steps in a `test` suite collided in the page's shared lexical scope), and top-level await is allowed. Main-world and completion-value semantics are unchanged. #37: core skill gains a hard rule — snapshot-first, never screenshot+coordinates to locate form fields/buttons; `snapshot -i` now pierces cross-origin iframes and lists their elements by @ref; screenshots are for visual checks only, and a full-page retina screenshot often exceeds an image reader's limits. --- cli/Cargo.lock | 2 +- cli/Cargo.toml | 2 +- cli/src/native/browser.rs | 18 +++++++++++++----- skill-data/core/SKILL.md | 11 +++++++++++ 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/cli/Cargo.lock b/cli/Cargo.lock index 03cb963..bd99350 100644 --- a/cli/Cargo.lock +++ b/cli/Cargo.lock @@ -290,7 +290,7 @@ checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" [[package]] name = "chrome-use" -version = "1.5.12" +version = "1.5.13" dependencies = [ "aes", "aes-gcm", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 0d2cddd..e03d871 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "chrome-use" -version = "1.5.12" +version = "1.5.13" edition = "2021" description = "Fast browser automation CLI for AI agents" license = "Apache-2.0" diff --git a/cli/src/native/browser.rs b/cli/src/native/browser.rs index b716a79..18d7527 100644 --- a/cli/src/native/browser.rs +++ b/cli/src/native/browser.rs @@ -1202,15 +1202,23 @@ impl BrowserManager { pub async fn evaluate(&self, script: &str, _args: Option) -> Result { let session_id = self.active_session_id()?.to_string(); + // `replMode: true` matches the DevTools console: top-level `let`/`const` + // can be re-declared across successive `eval`s instead of throwing + // "Identifier 'x' has already been declared" (issue #38 — independent + // `eval` steps in a test suite collided in the page's shared lexical + // scope), and top-level `await` is allowed. Completion-value and + // main-world semantics are unchanged. Built as raw params so the other + // ~28 EvaluateParams literals don't all need a new field. let result: EvaluateResult = self .client .send_command_typed( "Runtime.evaluate", - &EvaluateParams { - expression: script.to_string(), - return_by_value: Some(true), - await_promise: Some(true), - }, + &json!({ + "expression": script, + "returnByValue": true, + "awaitPromise": true, + "replMode": true, + }), Some(&session_id), ) .await?; diff --git a/skill-data/core/SKILL.md b/skill-data/core/SKILL.md index d2075bd..81e18f4 100644 --- a/skill-data/core/SKILL.md +++ b/skill-data/core/SKILL.md @@ -36,6 +36,17 @@ Refs (`@e1`, `@e2`, ...) are assigned fresh on every snapshot. They become submits, dynamic re-renders, dialog opens. Always re-snapshot before your next ref interaction. +> **Hard rule: snapshot-first, never screenshot-to-locate.** For form fields and +> buttons, ALWAYS `snapshot -i` and act on refs/selectors. Do **not** reach for +> `screenshot` + coordinate clicks to find or hit an element — `snapshot -i` now +> pierces **cross-origin iframes** (embedded Google Payments / Stripe / checkout / +> KYC forms) and lists their elements by `@ref`, including input values. Use +> coordinates only for canvas/WebGL, or when `snapshot` genuinely returns nothing +> for your target. Screenshots are for *visual verification you report*, never the +> agent's own input — and a full-page `screenshot` of a real retina browser is +> often too large for an image reader anyway. (If you ever feel you *need* a +> screenshot to read state or locate something, that's a bug — please file it.) + > **Snapshot-first, always. Never default to `screenshot` + coordinate clicking > for form fields or buttons.** Run `snapshot -i` and act on `@refs`. Use > coordinates only for canvas/WebGL, or when `snapshot` genuinely returns nothing