fix(eval): replMode so successive evals can re-declare let/const; snapshot-first skill rule (#37, #38)

#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.
This commit is contained in:
leeguooooo
2026-06-17 01:15:31 +09:00
parent 1ac8ef7732
commit f714c7920b
4 changed files with 26 additions and 7 deletions
+1 -1
View File
@@ -290,7 +290,7 @@ checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
[[package]] [[package]]
name = "chrome-use" name = "chrome-use"
version = "1.5.12" version = "1.5.13"
dependencies = [ dependencies = [
"aes", "aes",
"aes-gcm", "aes-gcm",
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "chrome-use" name = "chrome-use"
version = "1.5.12" version = "1.5.13"
edition = "2021" edition = "2021"
description = "Fast browser automation CLI for AI agents" description = "Fast browser automation CLI for AI agents"
license = "Apache-2.0" license = "Apache-2.0"
+13 -5
View File
@@ -1202,15 +1202,23 @@ impl BrowserManager {
pub async fn evaluate(&self, script: &str, _args: Option<Value>) -> Result<Value, String> { pub async fn evaluate(&self, script: &str, _args: Option<Value>) -> Result<Value, String> {
let session_id = self.active_session_id()?.to_string(); 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 let result: EvaluateResult = self
.client .client
.send_command_typed( .send_command_typed(
"Runtime.evaluate", "Runtime.evaluate",
&EvaluateParams { &json!({
expression: script.to_string(), "expression": script,
return_by_value: Some(true), "returnByValue": true,
await_promise: Some(true), "awaitPromise": true,
}, "replMode": true,
}),
Some(&session_id), Some(&session_id),
) )
.await?; .await?;
+11
View File
@@ -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 submits, dynamic re-renders, dialog opens. Always re-snapshot before your
next ref interaction. 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 > **Snapshot-first, always. Never default to `screenshot` + coordinate clicking
> for form fields or buttons.** Run `snapshot -i` and act on `@refs`. Use > for form fields or buttons.** Run `snapshot -i` and act on `@refs`. Use
> coordinates only for canvas/WebGL, or when `snapshot` genuinely returns nothing > coordinates only for canvas/WebGL, or when `snapshot` genuinely returns nothing