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]]
name = "chrome-use"
version = "1.5.12"
version = "1.5.13"
dependencies = [
"aes",
"aes-gcm",
+1 -1
View File
@@ -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"
+13 -5
View File
@@ -1202,15 +1202,23 @@ impl BrowserManager {
pub async fn evaluate(&self, script: &str, _args: Option<Value>) -> Result<Value, 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
.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?;