Files
GenericAgent/memory/web_setup_sop.md

43 lines
2.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Web 工具链初始化执行 SOP
若 web_scan 和 web_execute_js 已测试可用,无需执行此 SOP。
仅供初始安装时code_run 可用但 web 工具尚未配置的场景。
## 目标
在仅具备系统级权限code_run建立 Web 交互能力web_scan / web_execute_js
## 前置:检测浏览器
```python
import shutil, subprocess
browser = "chrome" if shutil.which("chrome") else "msedge" # Edge内置必存在Chrome可选
```
## 阶段一:安装 Tampermonkey (手动)
**状态**: 尚未实现自动化,需用户手动操作。
1.`start` 打开扩展商店页面(自动适配浏览器):
- Chrome: `start "" "https://chromewebstore.google.com/detail/篡改猴测试版/gcalenpjmijncebpfijmoaglllgpjagf"`
- Edge: `start "" "https://microsoftedge.microsoft.com/addons/detail/tampermonkey/iikmkjmpaadaobahmlepeloendndfphd"`
2. 提示用户点击"安装"并确认。
## 阶段二:安装 ljq_web_driver.user.js
**脚本路径**: `../assets/ljq_web_driver.user.js`
### 方案A自动化优先
本地 HTTP 服务器 + TM 中间页,用 `start` 命令打开:
1. Python 启动 `http.server` 托管脚本Content-Type: text/javascript
2. `start "" "https://www.tampermonkey.net/script_installation.php#url=http://127.0.0.1:{port}/ljq_web_driver.user.js"`
- ⚠️ 以上步骤均须用 `Popen` 非阻塞执行,禁止 `subprocess.run`,否则阻塞 agent
3. TM 秒弹安装确认,用户点"安装"即可
### 方案B手动 fallback
若方案A失败用剪贴板
1. 读取脚本内容 → `pyperclip.copy()`
2. 通知用户在 TM 中【新建脚本 → 全选 → 粘贴 → 保存】
## 阶段三:验证
调用 `web_scan` 或注入 JS 心跳检测,确认脚本已生效。
## 避坑 (Chromium untrusted 拦截)
- ❌ 直接导航到 `localhost/.user.js` → Chromium 弹 untrusted 拦截 + "另存为"延迟约1分钟
- ✅ 必须用 `start` 命令(系统级)打开 TM 中间页 URL → 秒弹安装,无拦截
- 此问题 Chrome 和 Edge 均存在Chromium 内核通病)