@sleepinsummer/agent-browser-cli 0.2.7 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -26
- package/README_EN.md +43 -28
- package/assets/tmwd_cdp_bridge/background.js +70 -8
- package/assets/tmwd_cdp_bridge/config.js +1 -1
- package/assets/tmwd_cdp_bridge/content.js +1 -0
- package/assets/tmwd_cdp_bridge/manifest.json +2 -1
- package/assets/tmwd_cdp_bridge/popup.html +17 -2
- package/assets/tmwd_cdp_bridge/popup.js +41 -2
- package/package.json +8 -6
- package/skills/agent-browser-cli/SKILL.md +27 -4
package/README.md
CHANGED
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
<a href="https://github.com/sleepinginsummer/agent-browser-cli"><img src="https://img.shields.io/badge/CLI-agentbrowsercli-2ea44f" alt="CLI agentbrowsercli"></a>
|
|
11
11
|
<a href="https://github.com/sleepinginsummer/agent-browser-cli/blob/main/LICENSE"><img src="https://img.shields.io/badge/License-MIT-green" alt="License MIT"></a>
|
|
12
12
|
<a href="https://github.com/sleepinginsummer/agent-browser-cli"><img src="https://img.shields.io/badge/sys-win%2Fmac%2Flinux-0078D6?labelColor=0078D6&color=C0C0C0" alt="sys win/mac/linux"></a>
|
|
13
|
-
<a href="https://github.com/sleepinginsummer/agent-browser-cli/releases"><img src="https://img.shields.io/badge/release-v0.2.
|
|
13
|
+
<a href="https://github.com/sleepinginsummer/agent-browser-cli/releases"><img src="https://img.shields.io/badge/release-v0.2.9-blue" alt="release v0.2.9"></a>
|
|
14
14
|
<a href="https://github.com/sleepinginsummer/agent-browser-cli/pulls"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen" alt="PRs welcome"></a>
|
|
15
|
+
<a href="https://github.com/sleepinginsummer/agent-browser-cli/stargazers"><img src="https://img.shields.io/github/stars/sleepinginsummer/agent-browser-cli?label=stars&color=yellow" alt="GitHub stars"></a>
|
|
15
16
|
</p>
|
|
16
17
|
|
|
17
18
|
[AI 一句话安装](#ai-一句话安装) · [手动安装](#手动安装) · [Chrome 扩展](#chrome-扩展) · [更新](#更新) · [卸载](#卸载) · [友情链接](#友情链接)
|
|
@@ -26,7 +27,7 @@
|
|
|
26
27
|
|
|
27
28
|
## 项目信息
|
|
28
29
|
|
|
29
|
-
- 当前版本:`0.2.
|
|
30
|
+
- 当前版本:`0.2.9`
|
|
30
31
|
- 支持平台:Windows(包括 WSL)/ Mac / Linux
|
|
31
32
|
- 浏览器:Chrome,需加载拓展 `assets/tmwd_cdp_bridge`
|
|
32
33
|
- Linux 支持前提:本机 Chrome / Chromium 需要支持安装扩展
|
|
@@ -112,17 +113,51 @@ cargo build --release
|
|
|
112
113
|
|
|
113
114
|
## Chrome 扩展
|
|
114
115
|
|
|
115
|
-
推荐从 [最新 Release](https://github.com/sleepinginsummer/agent-browser-cli/releases/latest) 下载 `chrome-extensions.zip`,下载后解压,Chrome 打开 `chrome://extensions`,开启“开发者模式”,点击“加载已解压的扩展程序”,选择解压后的 `tmwd_cdp_bridge` 目录。
|
|
116
|
+
1. 推荐从 [最新 Release](https://github.com/sleepinginsummer/agent-browser-cli/releases/latest) 下载 `chrome-extensions.zip`,下载后解压,Chrome 打开 `chrome://extensions`,开启“开发者模式”,点击“加载已解压的扩展程序”,选择解压后的 `tmwd_cdp_bridge` 目录。
|
|
116
117
|
|
|
117
|
-
本地源码构建时,也可以直接加载扩展目录:
|
|
118
|
+
2. 本地源码构建时,也可以直接加载扩展目录:
|
|
118
119
|
|
|
119
120
|
```text
|
|
120
121
|
assets/tmwd_cdp_bridge
|
|
121
122
|
```
|
|
122
123
|
|
|
123
|
-
Chrome 需要至少打开一个正常网页标签页,不要只停留在 `about:blank` 或 `chrome://` 页面。
|
|
124
|
+
3. Chrome 需要至少打开一个正常网页标签页,不要只停留在 `about:blank` 或 `chrome://` 页面。
|
|
125
|
+
4. 扩展连接后会在页面右侧显示 Chrome 插件提示角标。角标支持拖动位置,鼠标悬浮时展开;10 秒无命令后自动隐藏,也可以点击 `本次隐藏` 手动隐藏,本次服务连接周期内不再显示,约 300 秒服务断开并下次重连后恢复。
|
|
126
|
+
|
|
127
|
+
### 自定义Chrome插件的ws监听端口
|
|
128
|
+
|
|
129
|
+
- `18765`:默认插件 WebSocket 端口,Chrome 扩展连接使用,可通过 `agent-browser-cli set-extension-port <port>` 修改。
|
|
130
|
+
- `18767`:CLI HTTP API 端口,供 CLI 复用会话,不能作为插件端口使用。
|
|
131
|
+
|
|
132
|
+
CLI 修改插件端口:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
agent-browser-cli set-extension-port 18766
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
该命令会写入配置文件;如果 daemon 正在运行,会自动重启 daemon,让新端口立即生效。
|
|
139
|
+
|
|
140
|
+
也可以手动修改配置文件。配置文件位于 `~/.agent-browser-cli/config.json`,不存在时会自动生成:
|
|
141
|
+
|
|
142
|
+
```json
|
|
143
|
+
{
|
|
144
|
+
"extension_port": 18765
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
手动修改示例:
|
|
149
|
+
|
|
150
|
+
```json
|
|
151
|
+
{
|
|
152
|
+
"extension_port": 18766
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
手动改配置后需要执行 `agent-browser-cli restart`,daemon 才会按新端口重新监听。
|
|
157
|
+
|
|
158
|
+
Chrome 插件 popup 中也可以修改插件端口并立即重连。插件端口必须和 CLI 配置中的 `extension_port` 一致。
|
|
159
|
+
|
|
124
160
|
|
|
125
|
-
扩展连接后会在页面右侧显示 Chrome 插件提示角标。角标支持拖动位置,鼠标悬浮时展开;10 秒无命令后自动隐藏,也可以点击 `本次隐藏` 手动隐藏,本次服务连接周期内不再显示,约 300 秒服务断开并下次重连后恢复。
|
|
126
161
|
|
|
127
162
|
## 快速自检
|
|
128
163
|
|
|
@@ -155,26 +190,13 @@ agent-browser-cli tabs
|
|
|
155
190
|
|
|
156
191
|
## 更新
|
|
157
192
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
./target/release/agent-browser-cli restart
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
如果 Chrome 扩展有更新,在 `chrome://extensions` 中重新加载 `assets/tmwd_cdp_bridge` 扩展。
|
|
165
|
-
|
|
166
|
-
当前扩展配置标识为:
|
|
167
|
-
|
|
168
|
-
```js
|
|
169
|
-
const TID = '__agent_browser_cli_bridge_26c9f1';
|
|
193
|
+
ai一句话更新
|
|
194
|
+
```text
|
|
195
|
+
请阅读 https://github.com/sleepinginsummer/agent-browser-cli/blob/main/AI_INSTALL.md,按说明更新 CLI、重新下载插件zip让用户指定位置,用户手动加载 Chrome 扩展,并更新相关 SKILL.md`。
|
|
170
196
|
```
|
|
171
197
|
|
|
172
|
-
|
|
198
|
+
如果 Chrome 扩展有更新,在 `chrome://extensions` 中重新下载zpi覆盖,然后重新加载 `assets/tmwd_cdp_bridge` 扩展。
|
|
173
199
|
|
|
174
|
-
```bash
|
|
175
|
-
mkdir -p ~/.agents/skills/agent-browser-cli
|
|
176
|
-
cp skills/agent-browser-cli/SKILL.md ~/.agents/skills/agent-browser-cli/SKILL.md
|
|
177
|
-
```
|
|
178
200
|
|
|
179
201
|
## 卸载
|
|
180
202
|
|
|
@@ -193,10 +215,7 @@ rm -rf ~/.agents/skills/agent-browser-cli
|
|
|
193
215
|
|
|
194
216
|
最后在 Chrome 扩展管理页中移除 `TMWD CDP Bridge` 扩展,或删除已加载的 `assets/tmwd_cdp_bridge` 扩展配置。
|
|
195
217
|
|
|
196
|
-
## 端口
|
|
197
218
|
|
|
198
|
-
- `18765`:底层 `TMWebDriver` WebSocket,Chrome 扩展连接使用。
|
|
199
|
-
- `18767`:外层 `agent-browser-cli` HTTP 服务,供 CLI 复用会话。
|
|
200
219
|
|
|
201
220
|
## 友情链接
|
|
202
221
|
|
package/README_EN.md
CHANGED
|
@@ -10,8 +10,9 @@ Browser perception · Page control · Chrome session reuse · CDP · Conditional
|
|
|
10
10
|
<a href="https://github.com/sleepinginsummer/agent-browser-cli"><img src="https://img.shields.io/badge/CLI-agentbrowsercli-2ea44f" alt="CLI agentbrowsercli"></a>
|
|
11
11
|
<a href="https://github.com/sleepinginsummer/agent-browser-cli/blob/main/LICENSE"><img src="https://img.shields.io/badge/License-MIT-green" alt="License MIT"></a>
|
|
12
12
|
<a href="https://github.com/sleepinginsummer/agent-browser-cli"><img src="https://img.shields.io/badge/sys-win%2Fmac%2Flinux-0078D6?labelColor=0078D6&color=C0C0C0" alt="sys win/mac/linux"></a>
|
|
13
|
-
<a href="https://github.com/sleepinginsummer/agent-browser-cli/releases"><img src="https://img.shields.io/badge/release-v0.2.
|
|
13
|
+
<a href="https://github.com/sleepinginsummer/agent-browser-cli/releases"><img src="https://img.shields.io/badge/release-v0.2.9-blue" alt="release v0.2.9"></a>
|
|
14
14
|
<a href="https://github.com/sleepinginsummer/agent-browser-cli/pulls"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen" alt="PRs welcome"></a>
|
|
15
|
+
<a href="https://github.com/sleepinginsummer/agent-browser-cli/stargazers"><img src="https://img.shields.io/github/stars/sleepinginsummer/agent-browser-cli?label=stars&color=yellow" alt="GitHub stars"></a>
|
|
15
16
|
</p>
|
|
16
17
|
|
|
17
18
|
[AI One-Line Install](#ai-one-line-install) · [Manual Installation](#manual-installation) · [Chrome Extension](#chrome-extension) · [Update](#update) · [Uninstall](#uninstall) · [Friendly Links](#friendly-links)
|
|
@@ -26,7 +27,7 @@ This project is not Selenium or Playwright. It is better suited for helping agen
|
|
|
26
27
|
|
|
27
28
|
## Project Info
|
|
28
29
|
|
|
29
|
-
- Current version: `0.2.
|
|
30
|
+
- Current version: `0.2.9`
|
|
30
31
|
- Supported platforms: Windows (including WSL) / Mac / Linux
|
|
31
32
|
- Browser: Chrome, with the `assets/tmwd_cdp_bridge` extension loaded
|
|
32
33
|
- Linux prerequisite: the local Chrome / Chromium build must support loading extensions
|
|
@@ -112,17 +113,49 @@ cargo build --release
|
|
|
112
113
|
|
|
113
114
|
## Chrome Extension
|
|
114
115
|
|
|
115
|
-
Recommended: download `chrome-extensions.zip` from the [latest Release](https://github.com/sleepinginsummer/agent-browser-cli/releases/latest), extract it, open `chrome://extensions` in Chrome, enable `Developer mode`, click `Load unpacked`, and select the extracted `tmwd_cdp_bridge` directory.
|
|
116
|
+
1. Recommended: download `chrome-extensions.zip` from the [latest Release](https://github.com/sleepinginsummer/agent-browser-cli/releases/latest), extract it, open `chrome://extensions` in Chrome, enable `Developer mode`, click `Load unpacked`, and select the extracted `tmwd_cdp_bridge` directory.
|
|
116
117
|
|
|
117
|
-
When building from local source, you can also load this extension directory directly:
|
|
118
|
+
2. When building from local source, you can also load this extension directory directly:
|
|
118
119
|
|
|
119
120
|
```text
|
|
120
121
|
assets/tmwd_cdp_bridge
|
|
121
122
|
```
|
|
122
123
|
|
|
123
|
-
Chrome needs at least one normal web page tab open. Do not leave it only on `about:blank` or `chrome://` pages.
|
|
124
|
+
3. Chrome needs at least one normal web page tab open. Do not leave it only on `about:blank` or `chrome://` pages.
|
|
125
|
+
4. After the extension is connected, a Chrome extension tip badge appears on the right side of the page. The badge position is draggable and expands on hover. It auto-hides after 10 seconds without commands, and you can also click `Hide for this session` to hide it manually. Manual hiding lasts for the current service connection cycle and resets after the service disconnects after about 300 seconds and reconnects.
|
|
124
126
|
|
|
125
|
-
|
|
127
|
+
### Custom Chrome Extension WebSocket Port
|
|
128
|
+
|
|
129
|
+
- `18765`: default extension WebSocket port, used by the Chrome extension. It can be changed with `agent-browser-cli set-extension-port <port>`.
|
|
130
|
+
- `18767`: CLI HTTP API port, used by the CLI to reuse the session. It cannot be used as the extension port.
|
|
131
|
+
|
|
132
|
+
Change the extension port from CLI:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
agent-browser-cli set-extension-port 18766
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
This command writes the config file. If the daemon is running, it restarts the daemon so the new port takes effect immediately.
|
|
139
|
+
|
|
140
|
+
You can also edit the config file manually. The config file is `~/.agent-browser-cli/config.json`. It is created automatically when missing:
|
|
141
|
+
|
|
142
|
+
```json
|
|
143
|
+
{
|
|
144
|
+
"extension_port": 18765
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Manual edit example:
|
|
149
|
+
|
|
150
|
+
```json
|
|
151
|
+
{
|
|
152
|
+
"extension_port": 18766
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
After manually editing the config file, run `agent-browser-cli restart` so the daemon listens on the new port.
|
|
157
|
+
|
|
158
|
+
The Chrome extension popup can also update the extension port and reconnect immediately. The popup port must match the CLI `extension_port` config.
|
|
126
159
|
|
|
127
160
|
## Quick Check
|
|
128
161
|
|
|
@@ -155,26 +188,13 @@ agent-browser-cli tabs
|
|
|
155
188
|
|
|
156
189
|
## Update
|
|
157
190
|
|
|
158
|
-
|
|
159
|
-
git pull
|
|
160
|
-
cargo build --release
|
|
161
|
-
./target/release/agent-browser-cli restart
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
If the Chrome extension has updates, reload the `assets/tmwd_cdp_bridge` extension in `chrome://extensions`.
|
|
191
|
+
AI one-line update:
|
|
165
192
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
```js
|
|
169
|
-
const TID = '__agent_browser_cli_bridge_26c9f1';
|
|
193
|
+
```text
|
|
194
|
+
Please read https://github.com/sleepinginsummer/agent-browser-cli/blob/main/AI_INSTALL.md, follow the instructions to update the CLI, download the extension zip again to the user-specified location, ask the user to manually load the Chrome extension, and update the related SKILL.md.
|
|
170
195
|
```
|
|
171
196
|
|
|
172
|
-
If
|
|
173
|
-
|
|
174
|
-
```bash
|
|
175
|
-
mkdir -p ~/.agents/skills/agent-browser-cli
|
|
176
|
-
cp skills/agent-browser-cli/SKILL.md ~/.agents/skills/agent-browser-cli/SKILL.md
|
|
177
|
-
```
|
|
197
|
+
If the Chrome extension has updates, download the zip again, overwrite the existing files, and reload the `assets/tmwd_cdp_bridge` extension in `chrome://extensions`.
|
|
178
198
|
|
|
179
199
|
## Uninstall
|
|
180
200
|
|
|
@@ -193,11 +213,6 @@ rm -rf ~/.agents/skills/agent-browser-cli
|
|
|
193
213
|
|
|
194
214
|
Finally, remove the `TMWD CDP Bridge` extension from Chrome's extension management page, or remove the loaded `assets/tmwd_cdp_bridge` extension configuration.
|
|
195
215
|
|
|
196
|
-
## Ports
|
|
197
|
-
|
|
198
|
-
- `18765`: underlying `TMWebDriver` WebSocket, used by the Chrome extension.
|
|
199
|
-
- `18767`: outer `agent-browser-cli` HTTP service, used by the CLI to reuse the session.
|
|
200
|
-
|
|
201
216
|
## Friendly Links
|
|
202
217
|
|
|
203
218
|
- [LINUX DO - A New Ideal Community](https://linux.do/)
|
|
@@ -16,9 +16,13 @@ chrome.runtime.onInstalled.addListener(() => {
|
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
let lastCommandAt = 0;
|
|
19
|
+
const DEFAULT_WS_PORT = 18765;
|
|
20
|
+
const CLI_API_PORT = 18767;
|
|
21
|
+
let wsPort = DEFAULT_WS_PORT;
|
|
19
22
|
|
|
20
23
|
async function handleExtMessage(msg, sender) {
|
|
21
24
|
if (msg.cmd === 'status') return handleStatus();
|
|
25
|
+
if (msg.cmd === 'setPort') return await handleSetPort(msg);
|
|
22
26
|
lastCommandAt = Date.now();
|
|
23
27
|
if (msg.cmd === 'cookies') return await handleCookies(msg, sender);
|
|
24
28
|
if (msg.cmd === 'cdp') return await handleCDP(msg, sender);
|
|
@@ -78,12 +82,27 @@ function handleStatus() {
|
|
|
78
82
|
ok: true,
|
|
79
83
|
data: {
|
|
80
84
|
wsConnected: !!ws && ws.readyState === WebSocket.OPEN,
|
|
81
|
-
wsUrl:
|
|
85
|
+
wsUrl: getWsUrl(),
|
|
86
|
+
wsPort,
|
|
82
87
|
lastCommandAt
|
|
83
88
|
}
|
|
84
89
|
};
|
|
85
90
|
}
|
|
86
91
|
|
|
92
|
+
async function handleSetPort(msg) {
|
|
93
|
+
const port = normalizePort(msg.port);
|
|
94
|
+
await saveWsPort(port);
|
|
95
|
+
reconnectWS();
|
|
96
|
+
return {
|
|
97
|
+
ok: true,
|
|
98
|
+
data: {
|
|
99
|
+
wsPort,
|
|
100
|
+
wsUrl: getWsUrl(),
|
|
101
|
+
wsConnected: !!ws && ws.readyState === WebSocket.OPEN
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
87
106
|
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
|
|
88
107
|
handleExtMessage(msg, sender).then(sendResponse);
|
|
89
108
|
return true;
|
|
@@ -250,11 +269,36 @@ function buildCdpScript(code) {
|
|
|
250
269
|
|
|
251
270
|
// --- WebSocket Client for TMWebDriver ---
|
|
252
271
|
let ws = null;
|
|
253
|
-
|
|
272
|
+
|
|
273
|
+
function normalizePort(port) {
|
|
274
|
+
const value = Number(port);
|
|
275
|
+
if (!Number.isInteger(value) || value < 1 || value > 65535) {
|
|
276
|
+
throw new Error('端口必须是 1-65535');
|
|
277
|
+
}
|
|
278
|
+
if (value === CLI_API_PORT) {
|
|
279
|
+
throw new Error('18767 是 agent-browser-cli API 端口,请换一个插件端口');
|
|
280
|
+
}
|
|
281
|
+
return value;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
async function loadWsPort() {
|
|
285
|
+
const data = await chrome.storage.local.get({ wsPort: DEFAULT_WS_PORT });
|
|
286
|
+
wsPort = normalizePort(data.wsPort);
|
|
287
|
+
return wsPort;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
async function saveWsPort(port) {
|
|
291
|
+
wsPort = normalizePort(port);
|
|
292
|
+
await chrome.storage.local.set({ wsPort });
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function getWsUrl() {
|
|
296
|
+
return `ws://127.0.0.1:${wsPort}`;
|
|
297
|
+
}
|
|
254
298
|
|
|
255
299
|
function scheduleProbe() {
|
|
256
300
|
// Use chrome.alarms to survive MV3 service worker suspension
|
|
257
|
-
chrome.alarms.create('tmwd-ws-probe', { delayInMinutes: 0.
|
|
301
|
+
chrome.alarms.create('tmwd-ws-probe', { delayInMinutes: 0.017 }); // ~1s
|
|
258
302
|
}
|
|
259
303
|
|
|
260
304
|
function scheduleKeepalive() {
|
|
@@ -266,7 +310,7 @@ async function isServerAlive() {
|
|
|
266
310
|
try {
|
|
267
311
|
const ctrl = new AbortController();
|
|
268
312
|
setTimeout(() => ctrl.abort(), 2000);
|
|
269
|
-
await fetch(
|
|
313
|
+
await fetch(`http://127.0.0.1:${wsPort}`, { signal: ctrl.signal });
|
|
270
314
|
return true; // Got HTTP response → port is listening
|
|
271
315
|
} catch (e) {
|
|
272
316
|
return false; // Network error (connection refused) or timeout → server not alive
|
|
@@ -372,12 +416,20 @@ async function handleWsExec(data) {
|
|
|
372
416
|
}
|
|
373
417
|
}
|
|
374
418
|
|
|
375
|
-
function connectWS() {
|
|
419
|
+
async function connectWS() {
|
|
420
|
+
await loadWsPort();
|
|
376
421
|
if (ws && ws.readyState <= 1) return; // CONNECTING or OPEN
|
|
422
|
+
if (!(await isServerAlive())) {
|
|
423
|
+
console.warn('[TMWD-WS] Server not ready, retrying later:', getWsUrl());
|
|
424
|
+
ws = null;
|
|
425
|
+
scheduleProbe();
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
377
428
|
ws = null;
|
|
378
|
-
|
|
429
|
+
const wsUrl = getWsUrl();
|
|
430
|
+
console.log('[TMWD-WS] Connecting to', wsUrl);
|
|
379
431
|
try {
|
|
380
|
-
ws = new WebSocket(
|
|
432
|
+
ws = new WebSocket(wsUrl);
|
|
381
433
|
} catch (e) {
|
|
382
434
|
console.error('[TMWD-WS] Constructor error:', e);
|
|
383
435
|
ws = null;
|
|
@@ -429,11 +481,21 @@ function connectWS() {
|
|
|
429
481
|
scheduleProbe();
|
|
430
482
|
};
|
|
431
483
|
ws.onerror = (e) => {
|
|
432
|
-
console.
|
|
484
|
+
console.warn('[TMWD-WS] Connection warning:', e);
|
|
433
485
|
// onclose will fire after this, which triggers reconnect
|
|
434
486
|
};
|
|
435
487
|
}
|
|
436
488
|
|
|
489
|
+
function reconnectWS() {
|
|
490
|
+
if (ws) {
|
|
491
|
+
try { ws.onclose = null; ws.close(); } catch (_) {}
|
|
492
|
+
}
|
|
493
|
+
ws = null;
|
|
494
|
+
chrome.alarms.clear('tmwd-ws-probe');
|
|
495
|
+
chrome.alarms.clear('tmwd-ws-keepalive');
|
|
496
|
+
connectWS();
|
|
497
|
+
}
|
|
498
|
+
|
|
437
499
|
// Initial connect + wake-up hooks
|
|
438
500
|
connectWS();
|
|
439
501
|
injectContentScriptsIntoExistingTabs();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
globalThis.__agent_browser_cli_TID = '__agent_browser_cli_bridge_26c9f1';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
;(function(){ if (/streamlit/i.test(document.title)) return;
|
|
2
|
+
const TID = globalThis.__agent_browser_cli_TID || '__agent_browser_cli_bridge_26c9f1';
|
|
2
3
|
if (window.__agentBrowserCliCleanup) window.__agentBrowserCliCleanup();
|
|
3
4
|
if (window.__agentBrowserCliObserverCleanup) window.__agentBrowserCliObserverCleanup();
|
|
4
5
|
document.querySelectorAll('#agent-browser-cli-ind,#agent-browser-cli-style').forEach(e => e.remove());
|
|
@@ -3,17 +3,32 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="utf-8">
|
|
5
5
|
<style>
|
|
6
|
-
body{width:420px;max-height:
|
|
6
|
+
body{width:420px;max-height:560px;margin:0;padding:8px;font:12px monospace;background:#1e1e1e;color:#d4d4d4;overflow-y:auto}
|
|
7
7
|
h3{margin:4px 0;color:#569cd6}
|
|
8
8
|
button{background:#264f78;color:#fff;border:none;padding:4px 12px;cursor:pointer;border-radius:3px;margin-bottom:6px}
|
|
9
9
|
button:hover{background:#37699e}
|
|
10
|
+
input{width:86px;background:#252526;color:#d4d4d4;border:1px solid #3c3c3c;border-radius:3px;padding:4px;font:12px monospace}
|
|
11
|
+
label{display:inline-flex;align-items:center;gap:6px;margin-right:6px}
|
|
12
|
+
.panel{margin-bottom:8px;padding:6px;background:#252526;border-radius:3px}
|
|
13
|
+
.row{display:flex;align-items:center;gap:6px;margin-top:6px}
|
|
14
|
+
.status{color:#9cdcfe}
|
|
15
|
+
.error{color:#f48771}
|
|
10
16
|
pre{white-space:pre-wrap;word-break:break-all;margin:0;padding:6px;background:#252526;border-radius:3px;max-height:420px;overflow-y:auto}
|
|
11
17
|
</style>
|
|
12
18
|
</head>
|
|
13
19
|
<body>
|
|
20
|
+
<h3>🔌 Bridge</h3>
|
|
21
|
+
<div class="panel">
|
|
22
|
+
<div id="bridgeStatus" class="status">读取连接状态...</div>
|
|
23
|
+
<div class="row">
|
|
24
|
+
<label>端口 <input id="port" type="number" min="1" max="65535"></label>
|
|
25
|
+
<button id="savePort">保存并重连</button>
|
|
26
|
+
</div>
|
|
27
|
+
<div id="portMsg"></div>
|
|
28
|
+
</div>
|
|
14
29
|
<h3>🍪 Cookies</h3>
|
|
15
30
|
<button id="refresh">刷新</button>
|
|
16
31
|
<pre id="out">点击刷新获取 cookies...</pre>
|
|
17
32
|
<script src="popup.js"></script>
|
|
18
33
|
</body>
|
|
19
|
-
</html>
|
|
34
|
+
</html>
|
|
@@ -1,10 +1,49 @@
|
|
|
1
1
|
document.addEventListener('DOMContentLoaded', () => {
|
|
2
|
-
const out = document.getElementById('out');
|
|
3
2
|
const btn = document.getElementById('refresh');
|
|
3
|
+
const savePortBtn = document.getElementById('savePort');
|
|
4
4
|
btn.addEventListener('click', fetchCookies);
|
|
5
|
+
savePortBtn.addEventListener('click', savePort);
|
|
6
|
+
refreshBridgeStatus();
|
|
5
7
|
fetchCookies();
|
|
6
8
|
});
|
|
7
9
|
|
|
10
|
+
async function refreshBridgeStatus() {
|
|
11
|
+
const status = document.getElementById('bridgeStatus');
|
|
12
|
+
const portInput = document.getElementById('port');
|
|
13
|
+
try {
|
|
14
|
+
const resp = await chrome.runtime.sendMessage({ cmd: 'status' });
|
|
15
|
+
if (!resp?.ok) throw new Error(resp?.error || 'unknown');
|
|
16
|
+
const data = resp.data || {};
|
|
17
|
+
portInput.value = data.wsPort || 18765;
|
|
18
|
+
status.textContent = `状态: ${data.wsConnected ? '已连接' : '未连接'} ${data.wsUrl || ''}`;
|
|
19
|
+
} catch (e) {
|
|
20
|
+
status.textContent = '状态读取失败: ' + e.message;
|
|
21
|
+
status.className = 'error';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function savePort() {
|
|
26
|
+
const portInput = document.getElementById('port');
|
|
27
|
+
const portMsg = document.getElementById('portMsg');
|
|
28
|
+
try {
|
|
29
|
+
const port = Number(portInput.value);
|
|
30
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
31
|
+
throw new Error('端口必须是 1-65535');
|
|
32
|
+
}
|
|
33
|
+
if (port === 18767) {
|
|
34
|
+
throw new Error('18767 是 agent-browser-cli API 端口,请换一个插件端口');
|
|
35
|
+
}
|
|
36
|
+
const resp = await chrome.runtime.sendMessage({ cmd: 'setPort', port });
|
|
37
|
+
if (!resp?.ok) throw new Error(resp?.error || 'unknown');
|
|
38
|
+
portMsg.textContent = `Success: 已保存端口 ${port},正在使用新端口重连`;
|
|
39
|
+
portMsg.className = 'status';
|
|
40
|
+
await refreshBridgeStatus();
|
|
41
|
+
} catch (e) {
|
|
42
|
+
portMsg.textContent = '保存失败: ' + e.message;
|
|
43
|
+
portMsg.className = 'error';
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
8
47
|
async function fetchCookies() {
|
|
9
48
|
const out = document.getElementById('out');
|
|
10
49
|
try {
|
|
@@ -21,4 +60,4 @@ async function fetchCookies() {
|
|
|
21
60
|
const str = resp.data.map(c => `${c.name}=${c.value}`).join('; ');
|
|
22
61
|
await navigator.clipboard.writeText(str);
|
|
23
62
|
} catch (e) { out.textContent = 'Error: ' + e.message; }
|
|
24
|
-
}
|
|
63
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sleepinsummer/agent-browser-cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.9",
|
|
4
4
|
"description": "Agent-oriented browser sensing and control CLI backed by a native Rust daemon.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -18,14 +18,16 @@
|
|
|
18
18
|
],
|
|
19
19
|
"scripts": {
|
|
20
20
|
"build": "cargo build --release",
|
|
21
|
+
"version": "node scripts/sync-optional-deps.mjs && git add package.json package-lock.json",
|
|
22
|
+
"prepack": "node scripts/sync-optional-deps.mjs",
|
|
21
23
|
"postinstall": "node npm/postinstall.js"
|
|
22
24
|
},
|
|
23
25
|
"optionalDependencies": {
|
|
24
|
-
"@sleepinsummer/agent-browser-cli-darwin-arm64": "0.2.
|
|
25
|
-
"@sleepinsummer/agent-browser-cli-darwin-x64": "0.2.
|
|
26
|
-
"@sleepinsummer/agent-browser-cli-linux-x64": "0.2.
|
|
27
|
-
"@sleepinsummer/agent-browser-cli-linux-arm64": "0.2.
|
|
28
|
-
"@sleepinsummer/agent-browser-cli-win32-x64": "0.2.
|
|
26
|
+
"@sleepinsummer/agent-browser-cli-darwin-arm64": "0.2.9",
|
|
27
|
+
"@sleepinsummer/agent-browser-cli-darwin-x64": "0.2.9",
|
|
28
|
+
"@sleepinsummer/agent-browser-cli-linux-x64": "0.2.9",
|
|
29
|
+
"@sleepinsummer/agent-browser-cli-linux-arm64": "0.2.9",
|
|
30
|
+
"@sleepinsummer/agent-browser-cli-win32-x64": "0.2.9"
|
|
29
31
|
},
|
|
30
32
|
"engines": {
|
|
31
33
|
"node": ">=18"
|
|
@@ -44,7 +44,7 @@ assets/tmwd_cdp_bridge
|
|
|
44
44
|
扩展配置必须存在:
|
|
45
45
|
|
|
46
46
|
```js
|
|
47
|
-
|
|
47
|
+
globalThis.__agent_browser_cli_TID = '__agent_browser_cli_bridge_26c9f1';
|
|
48
48
|
```
|
|
49
49
|
|
|
50
50
|
对应文件:
|
|
@@ -72,13 +72,36 @@ agent-browser-cli restart
|
|
|
72
72
|
```
|
|
73
73
|
|
|
74
74
|
常驻服务端口:
|
|
75
|
-
- `18765
|
|
76
|
-
- `18767`:外层 `agent-browser-cli` HTTP
|
|
75
|
+
- `18765`:默认插件 WebSocket 端口,Chrome 扩展连接使用,可通过插件 popup 或 `agent-browser-cli set-extension-port <port>` 修改。
|
|
76
|
+
- `18767`:外层 `agent-browser-cli` HTTP API 端口,供 CLI 复用会话,不能作为插件端口使用。
|
|
77
|
+
|
|
78
|
+
插件端口配置文件:
|
|
79
|
+
|
|
80
|
+
```text
|
|
81
|
+
~/.agent-browser-cli/config.json
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
最小配置:
|
|
85
|
+
|
|
86
|
+
```json
|
|
87
|
+
{
|
|
88
|
+
"extension_port": 18765
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
CLI 修改插件端口:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
agent-browser-cli set-extension-port 18766
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Chrome 插件 popup 也可以修改插件端口并立即重连。插件端口必须和 CLI 配置中的 `extension_port` 一致。
|
|
77
99
|
|
|
78
100
|
成功标志:
|
|
79
101
|
- 返回 `status=success`
|
|
80
102
|
- 能看到 `tabs_count`
|
|
81
|
-
-
|
|
103
|
+
- `agent-browser-cli status` 中 `ports.extension.matched=true`
|
|
104
|
+
- `agent-browser-cli status` 中 `connection.extension_connected=true`
|
|
82
105
|
|
|
83
106
|
## 推荐 CLI 调用
|
|
84
107
|
|