fix: pass expected_domain to wrapped browser scripts
The `expected_domain` was removed from args for normalization but never re-inserted, causing JS scripts to receive empty expected_domain and report "missing_expected_domain" errors. 🤖 Generated with [Qoder][https://qoder.com]
This commit is contained in:
52
docs/superpowers/plans/2026-04-13-expected-domain-arg-fix.md
Normal file
52
docs/superpowers/plans/2026-04-13-expected-domain-arg-fix.md
Normal file
@@ -0,0 +1,52 @@
|
||||
# Expected Domain Arg Fix Implementation Plan
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||||
|
||||
**Goal:** Fix browser_script_skill_tool to pass expected_domain to wrapped JS scripts.
|
||||
|
||||
**Architecture:** Insert the normalized expected_domain back into args HashMap after domain normalization, before script wrapping.
|
||||
|
||||
**Tech Stack:** Rust, serde_json
|
||||
|
||||
---
|
||||
|
||||
## Files
|
||||
|
||||
- Modify: `src/compat/browser_script_skill_tool.rs:210` - Insert expected_domain back into args
|
||||
|
||||
---
|
||||
|
||||
### Task 1: Insert expected_domain into args
|
||||
|
||||
**Files:**
|
||||
- Modify: `src/compat/browser_script_skill_tool.rs:210`
|
||||
|
||||
- [ ] **Step 1: Add expected_domain to args after normalization**
|
||||
|
||||
Edit `src/compat/browser_script_skill_tool.rs`, insert after line 209 (`eprintln!("[execute_browser_script_impl] expected_domain: {}", expected_domain);`):
|
||||
|
||||
```rust
|
||||
args.insert("expected_domain".to_string(), Value::String(expected_domain.clone()));
|
||||
```
|
||||
|
||||
The context around line 209-211 should look like this after the edit:
|
||||
|
||||
```rust
|
||||
eprintln!("[execute_browser_script_impl] expected_domain: {}", expected_domain);
|
||||
args.insert("expected_domain".to_string(), Value::String(expected_domain.clone()));
|
||||
|
||||
for required_arg in tool.args.keys() {
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Run tests to verify the fix**
|
||||
|
||||
Run: `cargo test browser_script_skill_tool --no-fail-fast -- --nocapture`
|
||||
|
||||
Expected: All tests pass, including `execute_browser_script_tool_runs_packaged_script_with_expected_domain`
|
||||
|
||||
- [ ] **Step 3: Commit**
|
||||
|
||||
```bash
|
||||
git add src/compat/browser_script_skill_tool.rs
|
||||
git commit -m "fix: pass expected_domain to wrapped browser scripts"
|
||||
```
|
||||
@@ -207,6 +207,7 @@ fn execute_browser_script_impl(
|
||||
}
|
||||
};
|
||||
eprintln!("[execute_browser_script_impl] expected_domain: {}", expected_domain);
|
||||
args.insert("expected_domain".to_string(), Value::String(expected_domain.clone()));
|
||||
|
||||
for required_arg in tool.args.keys() {
|
||||
if !args.contains_key(required_arg) {
|
||||
@@ -233,6 +234,8 @@ fn execute_browser_script_impl(
|
||||
|
||||
let wrapped_script = wrap_browser_script(&script_body, &Value::Object(args.clone()));
|
||||
eprintln!("[execute_browser_script_impl] 包装后脚本长度: {} 字节", wrapped_script.len());
|
||||
eprintln!("[execute_browser_script_impl] 包装后脚本前500字符: {}",
|
||||
if wrapped_script.len() > 500 { &wrapped_script[..500] } else { &wrapped_script });
|
||||
eprintln!("[execute_browser_script_impl] 调用 browser_tool.invoke(Action::Eval)...");
|
||||
|
||||
let target_url = format!("http://{}", expected_domain);
|
||||
|
||||
@@ -105,7 +105,8 @@ async fn execute_browser_script_tool_runs_packaged_script_with_expected_domain()
|
||||
..
|
||||
} if action == &Action::Eval
|
||||
&& security.expected_domain == "www.zhihu.com"
|
||||
&& params["script"].as_str().unwrap().contains("const args = {\"top_n\":\"10\"};")
|
||||
&& params["script"].as_str().unwrap().contains("\"expected_domain\":\"www.zhihu.com\"")
|
||||
&& params["script"].as_str().unwrap().contains("\"top_n\":\"10\"")
|
||||
&& params["script"].as_str().unwrap().contains("source: \"packaged script\"")
|
||||
));
|
||||
}
|
||||
@@ -278,7 +279,8 @@ return {
|
||||
..
|
||||
} if action == &Action::Eval
|
||||
&& security.expected_domain == "www.zhihu.com"
|
||||
&& params["script"].as_str().unwrap().contains("const args = {\"top_n\":\"10\"};")
|
||||
&& params["script"].as_str().unwrap().contains("\"expected_domain\":\"www.zhihu.com\"")
|
||||
&& params["script"].as_str().unwrap().contains("\"top_n\":\"10\"")
|
||||
&& params["script"].as_str().unwrap().contains("return {")
|
||||
));
|
||||
}
|
||||
@@ -360,7 +362,8 @@ return {
|
||||
..
|
||||
} if action == &Action::Eval
|
||||
&& security.expected_domain == "www.zhihu.com"
|
||||
&& params["script"].as_str().unwrap().contains("const args = {\"top_n\":\"10条\"};")
|
||||
&& params["script"].as_str().unwrap().contains("\"expected_domain\":\"www.zhihu.com\"")
|
||||
&& params["script"].as_str().unwrap().contains("\"top_n\":\"10条\"")
|
||||
&& params["script"].as_str().unwrap().contains("rows: [[1, \"标题\", args.top_n]]")
|
||||
));
|
||||
}
|
||||
@@ -444,7 +447,8 @@ return {
|
||||
..
|
||||
} if action == &Action::Eval
|
||||
&& security.expected_domain == "www.zhihu.com"
|
||||
&& params["script"].as_str().unwrap().contains("const args = {\"period\":\"2026-04\"};")
|
||||
&& params["script"].as_str().unwrap().contains("\"expected_domain\":\"www.zhihu.com\"")
|
||||
&& params["script"].as_str().unwrap().contains("\"period\":\"2026-04\"")
|
||||
&& params["script"].as_str().unwrap().contains("sheet_name")
|
||||
));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user