@seekskyworld/open-browser 0.2.0 → 0.3.0

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.
Files changed (53) hide show
  1. package/Docs/open-browser-api.d.ts +13 -9
  2. package/Docs//350/267/250/345/271/263/345/217/260/350/257/225/347/224/250/344/270/216/345/217/221/350/241/214.md +6 -6
  3. package/README.md +4 -4
  4. package/README.zh-CN.md +4 -4
  5. package/access-registry.mjs +8 -3
  6. package/action-execution.mjs +30 -5
  7. package/api-contract.mjs +6 -6
  8. package/browser-extension/manifest.json +1 -1
  9. package/browser-extension/newtab.js +1 -0
  10. package/browser-extension/phase-labels.js +1 -1
  11. package/browser-extension/popup.html +3 -1
  12. package/browser-extension/popup.js +33 -13
  13. package/browser-extension/tab-action.js +3 -2
  14. package/browser-extension/worker.js +3 -3
  15. package/capability-matrix.mjs +1 -1
  16. package/chromium-host.mjs +6 -10
  17. package/chromium-shell.mjs +2 -2
  18. package/cli.mjs +22 -22
  19. package/contract-validation.mjs +1 -1
  20. package/desktop/Info.plist +2 -2
  21. package/desktop/WorkspacePanel.m +3 -2
  22. package/desktop/build-macos.mjs +6 -3
  23. package/desktop/notarize-macos.mjs +54 -10
  24. package/desktop/sign.mjs +17 -2
  25. package/desktop/verify-macos-release.mjs +21 -13
  26. package/desktop/verify-version.mjs +22 -2
  27. package/engine-service.mjs +85 -26
  28. package/managed-input.mjs +22 -5
  29. package/mcp-http.mjs +9 -9
  30. package/mcp-server.mjs +23 -7
  31. package/mcp.mjs +1 -0
  32. package/package.json +6 -5
  33. package/page-activity.mjs +2 -1
  34. package/page-observation.mjs +4 -1
  35. package/receipt-store.mjs +17 -7
  36. package/runtime.mjs +2 -2
  37. package/sdk.mjs +24 -14
  38. package/service.mjs +36 -20
  39. package/skill-links.mjs +72 -18
  40. package/skills/open-browser/SKILL.md +8 -97
  41. package/skills/open-browser/references/macos.md +3 -0
  42. package/skills/open-browser/{SKILL.windows.md → references/operations.md} +7 -60
  43. package/skills/open-browser/references/recovery.md +36 -0
  44. package/skills/open-browser/references/windows.md +3 -0
  45. package/skills/open-browser/scripts/bootstrap.mjs +77 -89
  46. package/skills/open-browser/scripts/guide.mjs +17 -0
  47. package/studio/studio.js +2 -2
  48. package/tab-adoption.mjs +9 -3
  49. package/tab-recovery.mjs +100 -0
  50. package/visual-page.mjs +17 -7
  51. package/workspace-lifecycle.mjs +18 -2
  52. package/workspace-state.mjs +57 -16
  53. package/skills/open-browser/SKILL.macos.md +0 -112
@@ -18,7 +18,7 @@ export interface WorkspaceInfo {
18
18
  pageAvailability:'managed'|'closed'|'unregistered'|'sync_pending';
19
19
  nextAction:'wait_for_sync'|'reattachPage'|'request_tab_selection'|'wait_for_agent_control';
20
20
  accountAlias?:string;
21
- pages: ReadonlyArray<PageHandle & { ownership:'user'|'agent'; syncState:'synced'|'not_required'|'sync_pending'; syncRevision:number; lastSyncedAt:number|null; documentId:string; origin: string; title: string; openerPageId?:string; openedByOperationId?:string }>;
21
+ pages: ReadonlyArray<PageHandle & { readyForAgent:boolean; ownership:'user'|'agent'; syncState:'synced'|'not_required'|'sync_pending'; syncRevision:number; lastSyncedAt:number|null; documentId:string; origin: string; title: string; openerPageId?:string; openedByOperationId?:string }>;
22
22
  activity: WorkspaceActivity;
23
23
  blockedOrigins?: Array<{origin:string; scope:'resource'|'navigation'; reason:string; resourceType:string}>;
24
24
  }
@@ -176,6 +176,7 @@ export interface OperationReceipt {
176
176
  stepKind?: PageAction['kind'];
177
177
  completedSteps: number;
178
178
  error?: string;
179
+ obstruction?:{targetBounds:{x:number;y:number;width:number;height:number};element:string;inDialog:boolean;inputGuard:string;cause:'foreground_dialog'|'element_intercepts_pointer'|'unknown';nextAction:'inspect_dialog'|'observe_target';dialogBounds?:{x:number;y:number;width:number;height:number}};
179
180
  observation?: PageObservation;
180
181
  delta?: {changed?: ObservedElement[]; textChanged:boolean; text?:string; added:Array<{role:string;name:string}>; removed:Array<{role:string;name:string}>};
181
182
  dialogIds?: string[];
@@ -188,7 +189,7 @@ export interface OperationReceipt {
188
189
 
189
190
  /** CLI and MCP call this surface through the same SDK. */
190
191
  export interface OpenBrowserV1 {
191
- capabilities(): Promise<{version:number;contractVersion?:number;methods?:readonly string[];limits?:Readonly<Record<string,number>>;privacy?:{
192
+ capabilities(options?:{signal?:AbortSignal}): Promise<{version:number;contractVersion?:number;methods?:readonly string[];limits?:Readonly<Record<string,number>>;privacy?:{
192
193
  profile:'strict'|'compatibility'|string;
193
194
  telemetry:'disabled';
194
195
  chromiumServices:'reduced'|'compatibility';
@@ -196,7 +197,7 @@ export interface OpenBrowserV1 {
196
197
  diagnostics:'redacted';
197
198
  credentials:'memory-scoped';
198
199
  };visual:{enabled:boolean;actions:readonly string[]}}>;
199
- captureVisual(page:PageHandle,options?:{region?:VisualRect;ref?:string}):Promise<VisualFrame>;
200
+ captureVisual(page:PageHandle,options?:{region?:VisualRect;ref?:string;liveCanvas?:boolean}):Promise<VisualFrame>;
200
201
  createWorkspace(options?: CreateWorkspaceOptions): Promise<WorkspaceInfo>;
201
202
  open(options: OpenOptions): Promise<PageHandle>;
202
203
  /** SDK convenience. Opens one URL and observes it with fresh document metadata. */
@@ -208,12 +209,13 @@ export interface OpenBrowserV1 {
208
209
  reattachPage(page:PageHandle, options?:{waitMs?:number}):Promise<PageObservation>;
209
210
  previewFinish(workspaceId:string, keepPageIds?:string[]):Promise<{previewId:string; keptPageIds:string[]; closedPageIds:string[]}>;
210
211
  canvasSnapshot(page:PageHandle):Promise<PageHandle & {documentId:string; controlGeneration:string; snapshotVersion:string;
211
- adapter:'react-flow'|'chat'|'unsupported'; nodes:Array<{id:string; label:string; selected:boolean}>;
212
+ adapter:'react-flow'|'chat'|'unsupported'; reason?:'canvas_without_semantic_adapter'|'no_supported_markup';
213
+ fallback?:{dom:'observe';visualStatus:string;visual?:'captureVisual';grant?:'admin.setPixelPermission'|'extension_pixel_permission';origin?:string}; nodes:Array<{id:string; label:string; selected:boolean}>;
212
214
  edges:Array<{id:string; label:string; selected:boolean; source?:string; target?:string}>; messages:Array<{role:string; text:string}>;
213
215
  attachments:Array<{label:string}>; truncated:boolean}>;
214
216
  observe(page: PageHandle & ObserveOptions): Promise<PageObservation>;
215
217
  /** SDK convenience. Observes and queues an action batch through one service request. */
216
- observeAndAct(page: PageHandle & ObserveOptions, request: {actions: readonly PageAction[];operationId?:string;observeAfter?:'full'|'delta';timeoutMs?:number}): Promise<{observation:PageObservation;receipt:OperationReceipt}>;
218
+ observeAndAct(page: PageHandle & ObserveOptions, request: {actions: readonly PageAction[];operationId?:string;waitMs?:number;observeAfter?:'full'|'delta';timeoutMs?:number}): Promise<{observation:PageObservation;receipt:OperationReceipt}>;
217
219
  runWorkflow(page:PageHandle,request:WorkflowRequest):Promise<OperationReceipt>;
218
220
  act(page: PageHandle, request: {
219
221
  operationId: string;
@@ -225,9 +227,9 @@ export interface OpenBrowserV1 {
225
227
  timeoutMs?: number;
226
228
  }): Promise<OperationReceipt>;
227
229
  /** SDK convenience. Observes immediately before acting and generates an operation ID when omitted. */
228
- actAfterObserve(page: PageHandle, request: {actions: readonly PageAction[];operationId?:string;observeAfter?:'full'|'delta';timeoutMs?:number}): Promise<{observation:PageObservation;receipt:OperationReceipt}>;
230
+ actAfterObserve(page: PageHandle, request: {actions: readonly PageAction[];operationId?:string;waitMs?:number;observeAfter?:'full'|'delta';timeoutMs?:number}): Promise<{observation:PageObservation;receipt:OperationReceipt}>;
229
231
  diagnoseOperation(workspaceId:string,operationId:string):Promise<{version:1;state:string;phase?:OperationReceipt['phase'];totalSteps?:number;completedSteps:number;dispatchRecorded:boolean;category:string;nextAction:string}>;
230
- getOperation(workspaceId: string, operationId: string): Promise<OperationReceipt>;
232
+ getOperation(workspaceId: string, operationId: string, options?:{waitMs?:number}): Promise<OperationReceipt>;
231
233
  finishWorkspace(workspaceId:string, keepPageIds:string[], operationId:string, previewId?:string): Promise<OperationReceipt>;
232
234
  /** SDK convenience. Generates a fresh idempotency key for finishing a workspace. */
233
235
  finish(workspaceId:string, keepPageIds?:string[]): Promise<OperationReceipt>;
@@ -238,12 +240,14 @@ export interface OpenBrowserV1 {
238
240
  readOutput(workspaceId:string, outputId:string, options?:{partName?:string;offset?:number;limit?:number}): Promise<OutputChunk>;
239
241
  cancelDownload(workspaceId:string,downloadId:string): Promise<WorkspaceDownload>;
240
242
  getRecoverySummary(workspaceId:string, options?:{after?:number;objectsAfter?:number;limit?:number}): Promise<{
241
- workspaceId:string; mode:WorkspaceInfo['mode']|'unavailable'; pages:Array<{pageId:string;next:'observe'|'handle_unavailable'; lastDisposition?:'released'|'closed'; pageAvailability:'managed'|'unregistered'|'closed'; nextAction:string}>;
243
+ workspaceId:string; mode:WorkspaceInfo['mode']|'unavailable'; closeReason?:'explicit_close'|'idle_timeout'|'finished'|'service_shutdown'|'open_failed'|'unknown'; pages:Array<{pageId:string;origin?:string;next:'observe'|'handle_unavailable'; lastDisposition?:'released'|'closed'; pageAvailability:'managed'|'restorable'|'unregistered'|'closed'; nextAction:string}>;
242
244
  deliveries:Array<{downloadId:string}>; outputs:Array<{outputId:string}>; operations:Array<OperationReceipt & {next:'verify_site'|'poll'|'already_completed'|'inspect_receipt'}>;
243
245
  nextCursor:number|null; nextObjectCursor:number|null;
244
246
  }>;
245
247
  listOperations(workspaceId:string, options?:{after?:number;limit?:number}): Promise<{operations:OperationReceipt[];nextCursor:number|null}>;
246
248
  eventCursor(workspaceId:string):Promise<{nextCursor:number}>;
249
+ waitForEvent(page:{workspaceId:string}, options:{after:number;kind:'page_bound';timeoutMs?:number}):
250
+ Promise<{event:null|{sequence:number;kind:string;state:string;pageId:string;resourceId:string};nextCursor:number}>;
247
251
  waitForEvent(page:PageHandle, options:{after:number;kind:'dialog'|'download'|'popup';operationId?:string;timeoutMs?:number}):
248
252
  Promise<{event:null|{sequence:number;kind:string;state:string;pageId:string;resourceId:string;operationId?:string};nextCursor:number}>;
249
253
  listEvents(workspaceId:string, options?:{after?:number;limit?:number}): Promise<{
@@ -279,7 +283,7 @@ export interface OpenBrowserHostV1 {
279
283
  previewPage(page: PageHandle): Promise<Omit<PageObservation, 'elements'>>;
280
284
  showPage(page: PageHandle): Promise<PageHandle>;
281
285
  takeControl(params: { workspaceId: string; pageId?: string; controlGeneration?: string }): Promise<WorkspaceInfo>;
282
- returnToAgent(params: { workspaceId: string; controlGeneration?: string }): Promise<WorkspaceInfo>;
286
+ returnToAgent(params: { workspaceId: string; pageId?:string; controlGeneration?: string }): Promise<WorkspaceInfo & {observation?:PageObservation;pageError?:{pageId:string;code:string}}>;
283
287
  grantOrigin(params:{workspaceId:string;controlGeneration:string;origin:string;scope:'resource'|'navigation'}):Promise<unknown>;
284
288
  resolveCredential(params:PageHandle & {documentId:string;controlGeneration:string;operationId:string;origin:string;credentialRef:string;value:string}):Promise<{credentialRef:string;saved:true}>;
285
289
  setCredential(params: {
@@ -26,7 +26,7 @@ Windows x64 下载 `open-browser-win32-x64.zip` 并完整解压,运行 `open-b
26
26
  | `npm run package:portable:all` | 依次生成 Windows、Linux 便携包 | 两个平台的归档和校验和 |
27
27
  | `npm run package:all` | 生成 macOS、Windows、Linux 全部本地发行包 | `dist/` 下全部平台归档 |
28
28
 
29
- macOS 正式公证发行仍使用 `npm run build:release-macos:arm64` 或 `npm run build:release-macos:x64`,然后运行 `npm run release:verify-macos`。本地 DMG 和 ZIP 适合安装测试,正式对外发布前需要完成 Apple 公证。
29
+ 每次公开发行都要提供 Apple Silicon 和 Intel 两份 DMG。两个架构分别使用 `npm run build:release-macos:arm64` 和 `npm run build:release-macos:x64`。脚本先公证应用并固化票据,再对最终 DMG 签名、单独提交 Apple 公证并固化镜像票据。使用 `npm run release:verify-macos -- dist/open-browser.app` 和 `npm run release:verify-macos -- dist/open-browser-x64.app` 分别验收。`npm run package:macos*` 只用于本地安装测试。
30
30
 
31
31
  开发构建使用 `npm run build:dev` 或 `npm run start:dev`。开发构建自动使用 `~/.open-browser/dev`,并隔离 PID、socket、回执数据库、Chromium profile 和 macOS 应用标识。稳定构建使用 `npm run build:stable` 或 `npm start`,数据目录为 `~/.open-browser`。
32
32
 
@@ -34,14 +34,14 @@ macOS 正式公证发行仍使用 `npm run build:release-macos:arm64` 或 `npm r
34
34
  | --- | --- | --- |
35
35
  | macOS arm64 开发构建 | `npm run browser:install`,然后 `npm run build:macos:arm64` | `dist/open-browser.app`,需要 arm64 macOS 和 Developer ID Application 签名证书 |
36
36
  | macOS x64 开发构建 | `npm run browser:install`,然后 `npm run build:macos:x64` | `dist/open-browser-x64.app`,需要 x64 macOS、Rosetta 下的 x64 Node,或 x64 CI runner |
37
- | macOS arm64 GitHub 发行 | `npm run build:release-macos:arm64` | 公证并固化票据的 `dist/open-browser-macos-arm64.zip` 及 SHA-256 |
38
- | macOS x64 GitHub 发行 | `npm run build:release-macos:x64` | 公证并固化票据的 `dist/open-browser-macos-x64.zip` 及 SHA-256 |
37
+ | macOS arm64 GitHub 发行 | `npm run build:release-macos:arm64` | 已公证并固化票据的 `dist/open-browser-macos-arm64.dmg`、ZIP 及 SHA-256 |
38
+ | macOS x64 GitHub 发行 | `npm run build:release-macos:x64` | 已公证并固化票据的 `dist/open-browser-macos-x64.dmg`、ZIP 及 SHA-256 |
39
39
  | Linux x64 | `node desktop/build-portable.mjs linux-x64` | `dist/open-browser-linux-x64.tar.gz` 和 SHA-256 文件 |
40
40
  | Windows x64 | `node desktop/build-portable.mjs win32-x64` | `dist/open-browser-win32-x64.zip` 和 SHA-256 文件 |
41
41
 
42
42
  在 Linux 或 macOS 运行 `shasum -a 256 -c 文件名.sha256`,在 Windows PowerShell 运行 `Get-FileHash 文件名 -Algorithm SHA256` 并与随附的 SHA-256 比较。便携包可在 macOS 交叉打包。在对应平台解压包后,进入解压目录,Linux 运行 `./node/bin/node verify.mjs .`,Windows 运行 `.\node\node.exe verify.mjs .`,检查实际归档能启动服务和扩展、创建工作区并通过 CLI 读取本地测试页面,再验证临时服务退出。
43
43
 
44
- 无需签名证书的贡献者可运行 `npm ci`、`npm run browser:install`、`node --test clients.test.mjs control.test.mjs engine-service.test.mjs`。Linux 和 Windows CI 还运行真实扩展登录、接管测试及解压后的服务验收。签名 macOS 构建机上运行 `npm run test:all` 和 `codesign --verify --strict --deep dist/open-browser.app`;检查实际可见标签打开、接管交回、普通标签不受影响及升级后登录态。正式发行运行 `npm run build:release-macos`,它会用 `xcrun notarytool` 提交公证,执行 `xcrun stapler staple`,重新生成含票据的 GitHub ZIP,并运行 `npm run release:verify-macos` 验收 Hardened Runtime、票据、Gatekeeper 和 SHA-256。
44
+ 无需签名证书的贡献者可运行 `npm ci`、`npm run browser:install`、`node --test clients.test.mjs control.test.mjs engine-service.test.mjs`。Linux 和 Windows CI 还运行真实扩展登录、接管测试及解压后的服务验收。签名 macOS 构建机上运行 `npm run test:all` 和 `codesign --verify --strict --deep dist/open-browser.app`;检查实际可见标签打开、接管交回、普通标签不受影响及升级后登录态。正式发行运行 `npm run build:release-macos:arm64` 或 `npm run build:release-macos:x64`,它会用 `xcrun notarytool` 提交公证,执行 `xcrun stapler staple`,生成含票据的 GitHub DMG 和 ZIP,并运行 `npm run release:verify-macos` 验收 Hardened Runtime、票据、Gatekeeper 和两个归档的 SHA-256。
45
45
 
46
46
  ### macOS 签名与公证凭据
47
47
 
@@ -55,13 +55,13 @@ macOS 正式公证发行仍使用 `npm run build:release-macos:arm64` 或 `npm r
55
55
 
56
56
  脚本也兼容现有 GoLutra 发布环境的变量名。若本机已有 `~/.golutra-macos-release.env`,可运行 `source ~/.golutra-macos-release.env` 后直接执行发行命令。`APPLE_SIGNING_IDENTITY`、`APPLE_API_KEY_PATH`、`APPLE_API_KEY`、`APPLE_API_ISSUER`、`APPLE_ID`、`APPLE_PASSWORD` 和 `APPLE_TEAM_ID` 会自动映射到 open-browser 的发行流程。
57
57
 
58
- 当前发行目标采用 GitHub ZIP。若需改变产物路径,可设置 `OPEN_BROWSER_NOTARY_ZIP` 或传入 `--zip`。公证完成后,使用 `npm run release:verify-macos`,并保存构建提交、系统架构、ZIP SHA-256、notarytool Request ID 和验收日志。
58
+ 当前发行目标采用 GitHub DMG 和 ZIP。若需改变产物路径,可设置 `OPEN_BROWSER_NOTARY_ZIP`、`OPEN_BROWSER_NOTARY_DMG` 或传入 `--zip`、`--dmg`。公证完成后,使用 `npm run release:verify-macos`,并保存构建提交、系统架构、DMG 和 ZIP SHA-256、notarytool Request ID 和验收日志。
59
59
 
60
60
  ## 发行记录
61
61
 
62
62
  核对 `Docs/THIRD-PARTY-NOTICES.md`、分发内 `app/third-party-packages.json`、Node LICENSE、引擎的 ABOUT 与运行中的 `chrome://credits/`。保存构建所用提交、系统和架构、Node/Chromium 版本、包 SHA-256、测试输出与已知限制。CI 执行构建和验收;对外发布版本、选定项目许可证及上传 macOS 公证均由项目所有者决定。
63
63
 
64
- 在项目根目录运行 `python3 desktop/archive-release.py snapshot` 会生成保留执行位、固定时间戳的源码归档和校验和,包含 Git 已跟踪和未忽略的源码。归档保存在 `dist/open-browser-source-0.2.0.tar.gz`。macOS 构建机可以用以下命令归档已签名应用,再比对发行包中的应用源文件、第三方声明与源码快照。在此期间保持工作树稳定。
64
+ 在项目根目录运行 `python3 desktop/archive-release.py snapshot` 会生成保留执行位、固定时间戳的源码归档和校验和,包含 Git 已跟踪和未忽略的源码。归档保存在 `dist/open-browser-source-0.3.0.tar.gz`。macOS 构建机可以用以下命令归档已签名应用,再比对发行包中的应用源文件、第三方声明与源码快照。在此期间保持工作树稳定。
65
65
 
66
66
  ```sh
67
67
  ditto -c -k --keepParent --sequesterRsrc dist/open-browser.app dist/open-browser-macos-arm64.zip
package/README.md CHANGED
@@ -13,7 +13,7 @@ open-browser is an open-source desktop browser for agents. It runs locally and s
13
13
  ## What you can do
14
14
 
15
15
  - **Run tasks in parallel.** Workspaces progress independently and actions on each page stay in order. The service keeps same-page actions ordered while independent workspaces run concurrently. Use `npm run test:unit` and `npm run test:contract` to reproduce the local regression suites.
16
- - **Use an existing signed-in tab.** Ask the agent to create a named workspace. Open the extension on the desired open-browser tab, choose that task, and pass the two-minute authorization to the agent. The tab stays open when the task finishes.
16
+ - **Use an existing signed-in tab.** Ask the agent to create a named workspace. Open the extension on the desired open-browser tab, choose that task, and approve control of that tab. The tab stays open when the task finishes.
17
17
  - **Share a live task with an agent.** Take over during sign-in, complete the form in place and hand the same tab back with its session intact. For routine sign-ins, bind a credential to the workspace and site so the agent can fill it by reference. [Workspace and handoff guide](Docs/控制台分组与接管方案.md)
18
18
  - **Keep Agent input visibly exclusive.** While a workspace is in Agent control, the managed page rejects human page input and shows the existing task border and action cursor. Each Agent action opens a scoped dispatch window, then the page locks again. Use **人工接管** to edit the page yourself and **交回 Agent** to resume.
19
19
  - **Pause safely for site verification.** When a site returns a recognized security challenge, the workspace stops Agent actions and shows **需要人工验证**. Take over the visible page, complete the site's own verification, then return control and observe again. open-browser does not hide automation signals or bypass the challenge.
@@ -37,7 +37,7 @@ To try the control API, run the integration test. It starts a temporary local se
37
37
  node --test service.integration.test.mjs
38
38
  ```
39
39
 
40
- To open the stable desktop browser, run `npm start`. Use `npm run start:dev` for an isolated development build with separate state, PID, socket, receipts and macOS app identity. The first macOS desktop build requires Xcode command line tools and a Developer ID Application certificate. If you already have a build, open `dist/open-browser.app`. For a public GitHub ZIP, set a notarytool profile or CI credentials and run `npm run build:release-macos`, then run `npm run release:verify-macos`. Windows and Linux support running from source and x64 portable builds. For a headless service, run `node service.mjs --headless`. [Platform prerequisites and packaging](Docs/跨平台试用与发行.md)
40
+ To open the stable desktop browser, run `npm start`. Use `npm run start:dev` for an isolated development build with separate state, PID, socket, receipts and macOS app identity. The first macOS desktop build requires Xcode command line tools and a Developer ID Application certificate. If you already have a build, open `dist/open-browser.app`. For public GitHub DMG and ZIP releases, set a notarytool profile or CI credentials and run `npm run build:release-macos:arm64` or `npm run build:release-macos:x64`, then run `npm run release:verify-macos`. Windows and Linux support running from source and x64 portable builds. For a headless service, run `node service.mjs --headless`. [Platform prerequisites and packaging](Docs/跨平台试用与发行.md)
41
41
 
42
42
  ## Try a handoff
43
43
 
@@ -59,11 +59,11 @@ Every new workspace must include a clear `name` task label. The label appears in
59
59
 
60
60
  The scoped npm package exposes the same implementation through separate entry points. Install it with `npm install @seekskyworld/open-browser`. Run `open-browser` for CLI calls, configure `open-browser-mcp` as an MCP stdio server, or run `open-browser-mcp-http` for an authenticated loopback MCP endpoint. JavaScript clients can import `OpenBrowserClient` from `@seekskyworld/open-browser`.
61
61
 
62
- Agents using the [open-browser Skill](skills/open-browser/SKILL.md) call the CLI through `skills/open-browser/scripts/open-browser`. The Skill starts the local open-browser app or portable service when needed and retries once after it becomes ready. Set `OPEN_BROWSER_AUTOSTART=0` to require an already running service. Start the app manually or run `npm start` when you want to open the desktop window before creating a task. Pass method arguments as JSON on standard input. Use `node cli.mjs --help` to list methods. Run `open-browser skill` to print the platform-matched guide without starting the service.
62
+ Agents using the [open-browser Skill](skills/open-browser/SKILL.md) call the CLI through `skills/open-browser/scripts/open-browser`. The launcher starts the local app or portable service if needed. It retries once when the service could not accept the request. If a write loses its reply, the launcher returns `RESPONSE_LOST`. Check the workspace or operation receipt before submitting again. Set `OPEN_BROWSER_AUTOSTART=0` to require an already running service. Start the app manually or run `npm start` when you want to open the desktop window before creating a task. Pass method arguments as JSON on standard input. Use `node cli.mjs --help` to list methods. Run `open-browser skill` to print the platform-matched guide without starting the service.
63
63
 
64
64
  The optional `open-browser-mcp-http` command binds only to loopback, uses the profile token as Bearer authentication, and serves `/mcp` for clients that require URL-based MCP configuration. Set `OPEN_BROWSER_MCP_HTTP_PORT` to choose a port.
65
65
 
66
- On the first Skill or service start, open-browser detects existing Skill directories for Codex, Claude Code, Cursor, Windsurf, Gemini CLI, Cline, Roo Code and OpenCode. It creates an `open-browser` relative symlink in each detected directory, preserving existing files and links. Windsurf's standard `~/.codeium/windsurf/skills` directory and its legacy `~/.windsurf/skills` directory are both supported. Set `OPEN_BROWSER_AUTO_INSTALL_SKILLS=0` to disable this behavior. Add agent-specific Skill directories with the `OPEN_BROWSER_AGENT_SKILL_DIRS` path-list variable.
66
+ At service startup and on the first Skill call, open-browser detects existing Skill directories for Codex, Claude Code, Cursor, Windsurf, Gemini CLI, Cline, Roo Code and OpenCode. It creates an `open-browser` relative symlink in each detected directory, preserving user files and unrelated links. Windows uses a directory junction when the account lacks permission to create symbolic links. Skill calls reuse a successful scan for ten minutes. Newly installed agents are discovered on the next service start or the first call after the cache expires. Run `node skill-links.mjs` from the package directory for an immediate scan. Windsurf's standard `~/.codeium/windsurf/skills` directory and its legacy `~/.windsurf/skills` directory are both supported. Set `OPEN_BROWSER_AUTO_INSTALL_SKILLS=0` to disable this behavior. Add agent-specific Skill directories with the `OPEN_BROWSER_AGENT_SKILL_DIRS` path-list variable.
67
67
 
68
68
  For one explicit URL, an agent can use one `open` call to create a workspace and open the page. This shortcut keeps Chromium's normal page network so cross-origin CSS, scripts, fonts and images render normally. Observation and actions remain bound to the target workspace and origin. Use `createWorkspace` when strict origin isolation is required.
69
69
 
package/README.zh-CN.md CHANGED
@@ -13,7 +13,7 @@ open-browser 是一个本机运行的开源 Agent 浏览器,自带 Chromium。
13
13
  ## 用它做什么
14
14
 
15
15
  - **后台并行处理网页。** 不同工作区可以同时推进,同一页的动作按顺序执行。服务保证同页动作按顺序执行,同时允许不同工作区并发。可运行 `npm run test:unit` 和 `npm run test:contract` 重现本机回归套件。
16
- - **把打开的标签页交给 Agent。** 让 Agent 创建命名任务,在 open-browser 中已登录的标签页打开扩展,选择任务并点「让 Agent 操作此页」。把面板里的授权交给 Agent 即可继续,任务结束后原标签会保留。
16
+ - **把打开的标签页交给 Agent。** 让 Agent 创建命名任务,在 open-browser 中已登录的标签页打开扩展,选择任务并点「让 Agent 操作此页」。Agent 即可在该任务中读取所选页面,任务结束后原标签会保留。
17
17
  - **人和 Agent 接力完成任务。** 登录需要你确认时,接管原标签就能继续操作,保留当前表单和登录态。交回后,Agent 重新观察页面再继续。你也可以预先为指定站点绑定凭据,让常规登录自动完成。[工作区与接管](Docs/控制台分组与接管方案.md)
18
18
  - **Agent 操作时锁定页面输入。** Agent 控制工作区时,受管页面会拒绝人工鼠标、触控板和键盘输入,同时显示任务边框和动作光标。每次 Agent 动作结束后立即恢复锁定。点击 **人工接管** 后可以直接编辑原页,完成后点击 **交回 Agent**。
19
19
  - **站点安全验证暂停。** 检测到站点返回安全验证挑战时,工作区会停止 Agent 操作并显示“需要人工验证”。用户在可见页面完成站点自己的验证后交回控制权,再重新观察。open-browser 不隐藏自动化信号,也不绕过验证。
@@ -37,7 +37,7 @@ npm run browser:install
37
37
  node --test service.integration.test.mjs
38
38
  ```
39
39
 
40
- **打开稳定桌面浏览器**,运行 `npm start`。开发构建使用 `npm run start:dev`,它会隔离开发状态目录、PID、socket、回执和 macOS 应用标识。macOS 首次启动会构建签名应用,需要 Xcode 命令行工具和 Developer ID Application 证书。公开发布 GitHub ZIP 时,配置 notarytool 钥匙串配置或 CI 凭据,运行 `npm run build:release-macos`,再运行 `npm run release:verify-macos`。Windows、Linux 支持从源码启动和 x64 便携包。仅需无头服务时运行 `node service.mjs --headless`。[各平台构建、系统依赖与校验](Docs/跨平台试用与发行.md)
40
+ **打开稳定桌面浏览器**,运行 `npm start`。开发构建使用 `npm run start:dev`,它会隔离开发状态目录、PID、socket、回执和 macOS 应用标识。macOS 首次启动会构建签名应用,需要 Xcode 命令行工具和 Developer ID Application 证书。公开发布 GitHub DMG 和 ZIP 时,配置 notarytool 钥匙串配置或 CI 凭据,运行 `npm run build:release-macos:arm64` 或 `npm run build:release-macos:x64`,再运行 `npm run release:verify-macos`。Windows、Linux 支持从源码启动和 x64 便携包。仅需无头服务时运行 `node service.mjs --headless`。[各平台构建、系统依赖与校验](Docs/跨平台试用与发行.md)
41
41
 
42
42
  本地生成可安装的 macOS 默认包可运行 `npm run package:macos`,它会同时生成 `.app`、ZIP 和带 `Applications` 快捷方式的 DMG。只需要 DMG 时运行 `npm run package:macos:dmg`。Windows、Linux 包分别使用 `npm run package:windows:x64` 和 `npm run package:linux:x64`。
43
43
 
@@ -61,9 +61,9 @@ CLI 和 MCP 都通过同一个 SDK 调用本机 API。服务端使用 Playwright
61
61
 
62
62
  Scoped npm 包提供同一套实现的多个入口。运行 `npm install @seekskyworld/open-browser` 后,使用 `open-browser` 调用 CLI,使用 `open-browser-mcp` 配置 MCP stdio 服务,或使用 `open-browser-mcp-http` 启动经过 Bearer 认证的本机回环 MCP 地址。JavaScript 客户端可以从 `@seekskyworld/open-browser` 导入 `OpenBrowserClient`。
63
63
 
64
- Agent 使用 [open-browser Skill](skills/open-browser/SKILL.md) 时,通过 `skills/open-browser/scripts/open-browser` 调用 CLI。Skill 会在需要时启动本机 open-browser 应用或便携服务,等待就绪后自动重试一次。设置 `OPEN_BROWSER_AUTOSTART=0` 可要求服务必须已运行。希望先打开桌面窗口时,也可以手动启动应用或执行 `npm start`。运行 `open-browser skill` 可以直接输出当前安装包对应平台的 Skill 指南,不会启动服务。
64
+ Agent 使用 [open-browser Skill](skills/open-browser/SKILL.md) 时,通过 `skills/open-browser/scripts/open-browser` 调用 CLI。启动器按需启动本机应用或便携服务。如果服务尚未接收请求,就绪后会重试一次。写操作发出后回包中断时会返回 `RESPONSE_LOST`,请先核对工作区或操作回执。设置 `OPEN_BROWSER_AUTOSTART=0` 可要求服务必须已运行。希望先打开桌面窗口时,也可以手动启动应用或执行 `npm start`。运行 `open-browser skill` 可以直接输出当前安装包对应平台的 Skill 指南,不会启动服务。
65
65
 
66
- 首次运行 Skill 或本机服务时,open-browser 会检测已经存在的 Codex、Claude Code、Cursor、Windsurf、Gemini CLI、Cline、Roo Code 和 OpenCode Skill 目录,并在其中创建 `open-browser` 相对符号链接。已有文件和非 open-browser 符号链接会保留。Windsurf 的标准目录 `~/.codeium/windsurf/skills` 和旧版目录 `~/.windsurf/skills` 都支持。设置 `OPEN_BROWSER_AUTO_INSTALL_SKILLS=0` 可关闭自动安装,也可以通过 `OPEN_BROWSER_AGENT_SKILL_DIRS` 路径列表补充其他 Agent 的 Skill 目录。
66
+ 本机服务每次启动以及首次调用 Skill 时,open-browser 会检测已经存在的 Codex、Claude Code、Cursor、Windsurf、Gemini CLI、Cline、Roo Code 和 OpenCode Skill 目录,并在其中创建 `open-browser` 相对符号链接。已有文件和指向其他内容的链接会保留。Windows 账号缺少创建符号链接的权限时,会使用目录联接。Skill 会复用最近十分钟内的成功扫描。新装的 Agent 会在服务下次启动或缓存过期后的首次调用时补链。在包目录运行 `node skill-links.mjs` 可立即扫描。Windsurf 的标准目录 `~/.codeium/windsurf/skills` 和旧版目录 `~/.windsurf/skills` 都支持。设置 `OPEN_BROWSER_AUTO_INSTALL_SKILLS=0` 可关闭自动安装,也可以通过 `OPEN_BROWSER_AGENT_SKILL_DIRS` 路径列表补充其他 Agent 的 Skill 目录。
67
67
 
68
68
  需要 URL 形式 MCP 配置时,可运行 `open-browser-mcp-http`。它只监听本机回环地址 `/mcp`,默认读取当前 profile 的 token 作为 Bearer 认证,端口可用 `OPEN_BROWSER_MCP_HTTP_PORT` 设置。
69
69
 
@@ -26,6 +26,9 @@ export class AccessRegistry {
26
26
  id TEXT PRIMARY KEY, owner TEXT NOT NULL, name TEXT NOT NULL DEFAULT '',
27
27
  agentName TEXT NOT NULL DEFAULT '', createdAt INTEGER NOT NULL DEFAULT 0,
28
28
  updatedAt INTEGER NOT NULL DEFAULT 0);
29
+ CREATE TABLE IF NOT EXISTS resumable_tabs(
30
+ task TEXT PRIMARY KEY REFERENCES tasks(id) ON DELETE CASCADE,
31
+ page TEXT NOT NULL, origin TEXT NOT NULL, entry TEXT NOT NULL, expires INTEGER NOT NULL);
29
32
  CREATE TABLE IF NOT EXISTS grants(client TEXT REFERENCES clients(id) ON DELETE CASCADE,
30
33
  task TEXT REFERENCES tasks(id) ON DELETE CASCADE,permission TEXT NOT NULL,PRIMARY KEY(client,task));`);
31
34
  const taskColumns = new Set(this.db.prepare('PRAGMA table_info(tasks)').all().map(field => field.name));
@@ -53,17 +56,19 @@ export class AccessRegistry {
53
56
  return typeof task === 'string' && this.db.prepare('SELECT permission FROM grants WHERE client=? AND task=?').get(client,task)?.permission;
54
57
  }
55
58
  async call(engine, client, method, params) {
56
- if (['capabilities','listWorkspaces','createWorkspace'].includes(method)) params = validateRequest(method,params);
59
+ if (['capabilities','listWorkspaces','createWorkspace','open'].includes(method)) params = validateRequest(method,params);
57
60
  if (method === 'capabilities') return engine.call(method,{},client);
58
- if (method === 'createWorkspace') {
61
+ if (method === 'createWorkspace' || method === 'open') {
59
62
  const info = await engine.call(method, params, client);
60
63
  if (client !== 'local' && !this.db.prepare('SELECT id FROM clients WHERE id=?').get(client)) {
61
64
  await engine.call('closeWorkspace', {workspaceId:info.workspaceId}, client);
62
65
  fail('forbidden');
63
66
  }
67
+ const workspace = engine.workspaces.get(info.workspaceId);
68
+ if (!workspace) fail('workspace_not_found');
64
69
  const now = Date.now();
65
70
  this.db.prepare('INSERT INTO tasks(id,owner,name,agentName,createdAt,updatedAt) VALUES(?,?,?,?,?,?)')
66
- .run(info.workspaceId, client, info.name || '', info.agentName || '', now, now);
71
+ .run(info.workspaceId, client, workspace.name, workspace.agentName, now, now);
67
72
  return info;
68
73
  }
69
74
  if (method === 'listWorkspaces') {
@@ -102,6 +102,21 @@ async function consumeClickProbe(handle, probeId, expectedClicks) {
102
102
  } catch { return false; }
103
103
  }
104
104
 
105
+ // Report only geometry and a small vocabulary of roles from the target frame.
106
+ function inspectObstruction(target) {
107
+ const rect = target.getBoundingClientRect();
108
+ const hit = document.elementFromPoint(rect.x + rect.width / 2, rect.y + rect.height / 2);
109
+ const blocked = hit && hit !== target && !target.contains(hit);
110
+ const element = blocked && ['button','div','dialog','section','aside','iframe'].includes(hit.localName)
111
+ ? hit.localName : blocked ? 'other' : 'unknown';
112
+ const dialog = blocked && hit.closest('dialog,[role="dialog"],[role="alertdialog"],[aria-modal="true"]');
113
+ const bounds = r => ({x:r.x,y:r.y,width:r.width,height:r.height});
114
+ return {targetBounds:bounds(rect), element, inDialog:!!dialog,
115
+ cause:dialog ? 'foreground_dialog' : blocked ? 'element_intercepts_pointer' : 'unknown',
116
+ nextAction:dialog ? 'inspect_dialog' : 'observe_target',
117
+ ...(dialog && {dialogBounds:bounds(dialog.getBoundingClientRect())})};
118
+ }
119
+
105
120
  async function waitActionable(service, ws, tab, op, el, kind, documentId, generation) {
106
121
  if (op.receipt.phase !== 'actionability') {
107
122
  op.receipt.phase = 'actionability';
@@ -109,6 +124,7 @@ async function waitActionable(service, ws, tab, op, el, kind, documentId, genera
109
124
  service.notify(ws);
110
125
  }
111
126
  const deadline = Math.min(Date.now() + 5000, op.deadline ?? Infinity);
127
+ let obscured = false;
112
128
  while (!op.cancel) {
113
129
  ensureBudget(op);
114
130
  service.requireControl(ws, generation);
@@ -119,15 +135,17 @@ async function waitActionable(service, ws, tab, op, el, kind, documentId, genera
119
135
  // one Playwright call. Avoid separate visibility and enabled RPCs for the
120
136
  // common pointer path.
121
137
  try {
122
- if (kind === 'hover') await el.hover({ trial: true, timeout: Math.max(1, deadline - Date.now()) });
123
- else await el.click({ trial: true, timeout: Math.max(1, deadline - Date.now()) });
138
+ // Bound each trial so a human takeover can drain a blocked click promptly.
139
+ const timeout = Math.max(1, Math.min(350, deadline - Date.now()));
140
+ if (kind === 'hover') await el.hover({trial:true, timeout});
141
+ else await el.click({trial:true, timeout});
124
142
  return;
125
143
  } catch (error) {
126
144
  if (error.name !== 'TimeoutError') throw error;
127
145
  if (!await el.evaluate(node => node.isConnected).catch(() => false)) fail('stale_ref');
128
146
  if (op.cancel) fail('operation_cancelled');
129
- if (Date.now() >= deadline)
130
- fail(error.message.includes('intercepts pointer events') ? 'target_obscured' : 'target_not_actionable');
147
+ if (error.message.includes('intercepts pointer events')) obscured = true;
148
+ if (Date.now() >= deadline) fail(obscured ? 'target_obscured' : 'target_not_actionable');
131
149
  await delay(40, undefined, {signal:op.controller.signal});
132
150
  continue;
133
151
  }
@@ -337,7 +355,14 @@ export async function perform(service, ws, tab, { documentId, controlGeneration,
337
355
  }
338
356
  }
339
357
  } catch (error) {
340
- if (!op.dispatched) throw error;
358
+ if (!op.dispatched) {
359
+ if (error.code === 'target_obscured' && tab.documentId === documentId && ws.generation === controlGeneration) {
360
+ const obstruction = await el.evaluate(inspectObstruction).catch(() => null);
361
+ if (obstruction) tab.actionObstruction = {operationId:receipt.operationId, documentId, controlGeneration,
362
+ origin, obstruction:{...obstruction,inputGuard:ws.inputGuardMode || 'unavailable'}};
363
+ }
364
+ throw error;
365
+ }
341
366
  if (clickProbe && !tab.dialog && await consumeClickProbe(el, clickProbe, action.kind === 'doubleClick' ? 2 : 1)) {
342
367
  receipt.completedSteps++;
343
368
  op.dispatched = false;
package/api-contract.mjs CHANGED
@@ -56,7 +56,7 @@ const definitions = {
56
56
  },['workspaceId','pageId','documentId','controlGeneration','operationId','workflow']],
57
57
 
58
58
  capabilities: ['Discover service version, enabled inputs, limits and privacy mode before using optional features.',{}],
59
- captureVisual: ['Capture approved masked viewport pixels. Coordinates use viewport CSS pixels.',{...page,region,ref:id},Object.keys(page)],
59
+ captureVisual: ['Capture approved masked viewport pixels. Coordinates use viewport CSS pixels. For an animated game set liveCanvas to bind input to its sole canvas across repaints.',{...page,region,ref:id,liveCanvas:{type:'boolean'}},Object.keys(page)],
60
60
  listWorkspaces: ['List the workspaces available to this agent.', {}],
61
61
  createWorkspace: ['Create a browser workspace. Every task must provide a clear non-empty name. Each subagent should pass its own display name in agentName.', {
62
62
  profileId:{type:'string',pattern:'^[a-z0-9][a-z0-9_-]{0,47}$'},
@@ -92,7 +92,7 @@ const definitions = {
92
92
  ...page, includeFrames:{type:'boolean'}, frameControls:{type:'boolean'},
93
93
  locator:object({role:id,name:id,within:object({role:id,name:id})},['role','name']),
94
94
  cursor:id, limit:{type:'integer',minimum:1,maximum:180}, name:id, region,
95
- operationId:id, timeoutMs:{type:'integer',minimum:1,maximum:60000},
95
+ operationId:id, waitMs:{type:'integer',minimum:1,maximum:10000}, timeoutMs:{type:'integer',minimum:1,maximum:60000},
96
96
  observeAfter:{enum:['full','delta']},
97
97
  actions:{type:'array',minItems:1,maxItems:32,items:action},
98
98
  }, ['workspaceId','pageId','operationId','actions']],
@@ -109,15 +109,15 @@ const definitions = {
109
109
  readOutput:['Read one locally delivered output in bounded base64 chunks. Use nextOffset to continue.',{...workspace,outputId:id,partName:{type:'string',maxLength:180},offset:{type:'integer',minimum:0},limit:{type:'integer',minimum:1,maximum:65536}},['workspaceId','outputId']],
110
110
  cancelDownload:['Cancel a download belonging to this workspace.',{...workspace,downloadId:id}],
111
111
  eventCursor:['Get the current workspace event cursor before triggering an action.',workspace],
112
- waitForEvent:['Wait for a matching page event. Reuse the same cursor to read it after reconnecting.',
113
- {...page,kind:{enum:['dialog','download','popup']},after:{type:'integer',minimum:0},operationId:id,
114
- timeoutMs:{type:'integer',minimum:1,maximum:10000}},[...Object.keys(page),'kind','after']],
112
+ waitForEvent:['Wait for a matching page event. Omit pageId for a workspace page_bound event after tab approval. Other kinds require pageId. Reuse the same cursor to read it after reconnecting.',
113
+ {...page,kind:{enum:['dialog','download','popup','page_bound']},after:{type:'integer',minimum:0},operationId:id,
114
+ timeoutMs:{type:'integer',minimum:1,maximum:10000}},['workspaceId','kind','after']],
115
115
  listEvents:['Poll redacted changes since a sequence number.',history,['workspaceId']],
116
116
  getRecoverySummary:['Read task recovery steps, delivered objects and page availability. Observe or verify before resuming.',{...history,objectsAfter:{type:'integer',minimum:0}},['workspaceId']],
117
117
  listOperations:['Read redacted receipt history.',history,['workspaceId']],
118
118
  finishWorkspace:['Call when the overall task is complete, before reporting success. Keep selected result tabs as ordinary tabs and remove the task group. Use an empty list when there are no results to keep.',{...operation,keepPageIds:{type:'array',uniqueItems:true,items:id},previewId:id},['workspaceId','operationId','keepPageIds']],
119
119
  diagnoseOperation: ['Preview a redacted diagnostic with the next safe action. Use it after a timeout, disconnect or outcome_unknown.', operation],
120
- getOperation: ['Read an operation receipt, including its completed step count.', operation],
120
+ getOperation: ['Read an operation receipt, including its completed step count. Set waitMs to wait briefly for a pending action.', {...operation,waitMs:{type:'integer',minimum:1,maximum:10000}},Object.keys(operation)],
121
121
  cancelOperation: ['Cancel the remaining steps of an operation.', operation],
122
122
  handOff: ['Hand control of the workspace to its user.', workspace],
123
123
  closeWorkspace: ['Close the workspace and its managed pages.', workspace],
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "open-browser",
4
- "version": "0.2.0",
4
+ "version": "0.3.0",
5
5
  "description": "管理本机 Agent 工作区与 Chromium 标签组",
6
6
  "key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAhZVSXIA/vfzO0jj4ebn25I3lbL//y8FbZUeQ8Q9shwfMWTbl3bsjcHzIITSGg5+NqVTAEB1AgjFZDi/Idoj+tgsvwQxXbMBzgdZA1tQMASXcbFRdVNTxWbRBSd4JXtsFfD7H6QeBwXuIHNqUeyQYD0sYn8Ot0c4KJCzsYshYPLU56+Lzdoy+7l6ydmmw31T4tpanZHJvUgyzATOjEekFJii+9IEI/G4BUGQhKdPqR/MBYiqzxgPB5WIr3w25z6bH5KC6wnUxblLQM0RAHa4hot38NOFul5JCW6BOLHEes7Pz3DOUpWFP+DFSkY42r0dt1Kh/5CFKr6ED3agcc+tB1wIDAQAB",
7
7
  "permissions": [
@@ -28,6 +28,7 @@ function friendlyError(error) {
28
28
 
29
29
  function stateLabel(workspace) {
30
30
  if (workspace.activity?.needsHumanVerification) return '需要人工验证';
31
+ if (workspace.activity?.needsVisualPermission) return '需要授权截图';
31
32
  if (workspace.activity?.needsCredential) return '等待凭据';
32
33
  return modes[workspace.mode] || phases[workspace.activity?.current?.phase] || phases[workspace.activity?.phase] || '待命';
33
34
  }
@@ -3,7 +3,7 @@
3
3
  globalThis.openBrowserPhaseLabels = Object.freeze({
4
4
  idle: '等待指令', queued: '已排队', running: '执行中', actionability: '检查目标',
5
5
  dispatching: '正在派发', waiting: '等待页面', verifying: '核对结果',
6
- needs_credential: '等待凭据', needs_human_verification: '需要人工验证', completed: '已完成', failed: '失败',
6
+ needs_credential: '等待凭据', needs_human_verification: '需要人工验证', needs_visual_permission: '需要授权截图', completed: '已完成', failed: '失败',
7
7
  cancelled: '已取消', outcome_unknown: '结果待核实',
8
8
  });
9
9
  globalThis.openBrowserModeLabels = Object.freeze({ agent: 'Agent 控制', human: '人工接管', transferring: '交接中' });
@@ -18,7 +18,8 @@
18
18
  <p id="adopt-site"></p>
19
19
  <label for="adopt-task">授权给哪个 Agent 任务</label><select id="adopt-task"></select>
20
20
  <label for="adopt-alias">账号别名(选填)</label><input id="adopt-alias" maxlength="48" placeholder="例如:工作账号">
21
- <div class="action"><button id="adopt" type="button">让 Agent 操作此页</button></div>
21
+ <label><input type="checkbox" id="resume-tab">重启时恢复上次浏览会话,并继续此页任务</label>
22
+ <div class="action"><button id="adopt" type="button">让 Agent 操作此页</button><button class="secondary" id="adopt-manual" type="button">生成备用授权码</button></div>
22
23
  <label id="adopt-result" hidden>将以下授权交给所选 Agent,两分钟内有效<input id="adopt-token" readonly></label>
23
24
  </section>
24
25
  <section id="workspace" hidden>
@@ -33,6 +34,7 @@
33
34
  <details id="uploads"><summary>授权上传文件</summary><p id="upload-origin"></p>
34
35
  <input id="upload-file" type="file"><div id="upload-list"></div></details>
35
36
  <details id="downloads" hidden><summary>任务下载</summary><div id="download-list"></div></details>
37
+ <button id="pixel-permission" type="button" class="secondary" hidden></button>
36
38
  <p id="visual-status" hidden></p>
37
39
  <details><summary>导出错误日志</summary>
38
40
  <p>导出当前任务的脱敏失败记录,便于排查问题。</p>
@@ -20,6 +20,7 @@ function describe(w) {
20
20
  if (w.mode === 'human') return '人工接管';
21
21
  if (w.mode === 'transferring') return '交接中';
22
22
  if (w.activity?.needsCredential) return '等待凭据';
23
+ if (w.activity?.needsVisualPermission) return '需要授权截图';
23
24
  const current = w.activity?.current;
24
25
  const stage = current?.dispatchState;
25
26
  if (stage) return stage === 'dispatched' ? '已派发' : '等待页面';
@@ -51,17 +52,25 @@ function clearToken() {
51
52
  el('adopt-token').value = '';
52
53
  el('adopt-result').hidden = true;
53
54
  }
54
- el('adopt-task').onchange = () => { clearToken(); el('adopt').disabled = !el('adopt-task').value; };
55
- el('adopt').onclick = () => perform(async () => {
56
- clearToken();
57
- const {id:targetId, origin} = ordinaryTarget;
58
- const reply = await call('offerCurrentTab',{workspaceId:el('adopt-task').value, tabId:popupTabId,
59
- targetId, origin, accountAlias:el('adopt-alias').value.trim()});
60
- el('adopt-token').value = JSON.stringify({workspaceId:reply.workspaceId,adoptionToken:reply.adoptionToken});
61
- el('adopt-result').hidden = false;
62
- el('adopt-token').select();
63
- tokenTimer = setTimeout(clearToken, Math.max(0, reply.expiresAt - Date.now()));
64
- });
55
+ el('adopt-task').onchange = () => { clearToken(); el('adopt-manual').disabled = el('adopt').disabled = !el('adopt-task').value; };
56
+ function authorizeTab(bindOnApproval) {
57
+ return perform(async () => {
58
+ clearToken();
59
+ const {id:targetId, origin} = ordinaryTarget;
60
+ const reply = await call('offerCurrentTab',{workspaceId:el('adopt-task').value, tabId:popupTabId,
61
+ targetId, origin, bindOnApproval, resumeOnRestart:el('resume-tab').checked, accountAlias:el('adopt-alias').value.trim()});
62
+ if (bindOnApproval && reply.pageId) {
63
+ notify('已将此页交给所选任务');
64
+ return;
65
+ }
66
+ el('adopt-token').value = JSON.stringify({workspaceId:reply.workspaceId,adoptionToken:reply.adoptionToken});
67
+ el('adopt-result').hidden = false;
68
+ el('adopt-token').select();
69
+ tokenTimer = setTimeout(clearToken, Math.max(0, reply.expiresAt - Date.now()));
70
+ });
71
+ }
72
+ el('adopt').onclick = () => authorizeTab(true);
73
+ el('adopt-manual').onclick = () => authorizeTab(false);
65
74
 
66
75
  let deliveryKey = '', finishId;
67
76
  function renderDelivery(w) {
@@ -192,7 +201,7 @@ async function sync() {
192
201
  const chooser = el('adopt-task');
193
202
  options(chooser, tasks.map(w => [w.workspaceId, workspaceTitle(w) + ' · ' + w.workspaceId.slice(0,8)]),
194
203
  tasks.some(w => w.workspaceId === chooser.value) ? chooser.value : tasks.length === 1 ? tasks[0].workspaceId : '');
195
- el('adopt').disabled = !chooser.value;
204
+ el('adopt-manual').disabled = el('adopt').disabled = !chooser.value;
196
205
  return;
197
206
  }
198
207
  const list = contextTab ? (selected ? [await call('getWorkspace', {workspaceId: selected })] : []) : await call('listWorkspaces');
@@ -212,7 +221,7 @@ async function sync() {
212
221
  options(el('workspaces'), entries, selected);
213
222
  const w = contextTab ? list[0] || null : selected ? await call('getWorkspace', { workspaceId: selected }) : null;
214
223
  const [captureReply, downloads, uploads] = w ? await Promise.all([
215
- call('visualStatus',{workspaceId:selected}).catch(()=>({})),
224
+ call('visualStatus',{workspaceId:selected,pageId:selectedTab}).catch(()=>({})),
216
225
  call('listDownloads',{workspaceId:selected}),
217
226
  call('listUploads',{workspaceId:selected}),
218
227
  ]) : [{}, [], []];
@@ -226,6 +235,17 @@ async function sync() {
226
235
  return button;
227
236
  }));
228
237
  renderDownloads(downloads);
238
+ const permission = captureReply.pagePermission;
239
+ const button = el('pixel-permission');
240
+ const pageId = selectedTab;
241
+ button.hidden = !permission;
242
+ if (permission) {
243
+ button.textContent = (permission.allow ? '撤销本任务截图授权 · ' : '允许本任务截图 · ') + permission.origin;
244
+ button.onclick = () => perform(() => call('setPagePixelPermission',{
245
+ workspaceId:w.workspaceId, pageId, documentId:permission.documentId, controlGeneration:w.controlGeneration,
246
+ origin:permission.origin, allow:!permission.allow
247
+ }));
248
+ }
229
249
  const status=el('visual-status');
230
250
  status.hidden=!capture;
231
251
  if(capture) status.textContent='最近画面采集 · '+capture.principalId+' · '+capture.origin+' · ('+
@@ -29,6 +29,7 @@ const actionStates = {
29
29
  verifying: ['✓', '#526675', '核对结果'],
30
30
  needs_credential: ['!', '#a72f24', '等待凭据'],
31
31
  needs_human_verification: ['!', '#a75d08', '需要人工验证'],
32
+ needs_visual_permission: ['!', '#a75d08', '需要授权截图'],
32
33
  completed: ['✓', '#526675', '已完成'],
33
34
  failed: ['!', '#a72f24', '执行失败'],
34
35
  outcome_unknown: ['?', '#a75d08', '结果待核实'],
@@ -52,10 +53,10 @@ async function writeAction(tabId, record) {
52
53
  return;
53
54
  }
54
55
  await chrome.storage.session.set({ [key]: record });
55
- const phase = record.mode !== 'agent' ? record.mode : record.needsHumanVerification ? 'needs_human_verification' : record.needsCredential ? 'needs_credential' : record.phase;
56
+ const phase = record.mode !== 'agent' ? record.mode : record.needsHumanVerification ? 'needs_human_verification' : record.needsVisualPermission ? 'needs_visual_permission' : record.needsCredential ? 'needs_credential' : record.phase;
56
57
  showRunning(tabId, ['running', 'actionability', 'dispatching', 'waiting', 'verifying'].includes(phase));
57
58
  const [text, color, status] = actionStates[phase] || actionStates.idle;
58
- const panel = phase === 'needs_credential' || phase === 'needs_human_verification' || phase === 'transferring' || !record.controlGeneration;
59
+ const panel = phase === 'needs_credential' || phase === 'needs_human_verification' || phase === 'needs_visual_permission' || phase === 'transferring' || !record.controlGeneration;
59
60
  const steps = { click: '点击', fill: '填写', fillCredential: '填写凭据' };
60
61
  const step = phase === 'running' && record.dispatchState ? (record.dispatchState === 'dispatched' ? '已派发' : '等待页面') : phase === 'running' ? steps[record.stepKind] : '';
61
62
  const hint = record.mode === 'human' ? '点击交回 Agent' : panel ? '点击打开工作区面板' : '点击接管';
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  importScripts('workspace-title.js', 'tab-action.js');
4
- globalThis.openBrowserGroupVersion = 12;
4
+ globalThis.openBrowserGroupVersion = 14;
5
5
 
6
6
  const groupsInProgress = new Map();
7
7
 
@@ -186,7 +186,7 @@ globalThis.openBrowserShow = async function () {
186
186
  };
187
187
 
188
188
  const newtabMethods = new Set(['listWorkspaces', 'listAgentHistory', 'listEvents']);
189
- const methods = new Set(['offerCurrentTab','listUploads','grantUpload','revokeUpload','respondDialog','listDownloads','cancelDownload','keepDownload','visualStatus','listOperations','listEvents', 'listWorkspaces', 'getWorkspace', 'takeControl', 'returnToAgent', 'grantOrigin', 'resolveCredential', 'finishWorkspace']);
189
+ const methods = new Set(['offerCurrentTab','listUploads','grantUpload','revokeUpload','respondDialog','listDownloads','cancelDownload','keepDownload','visualStatus','setPagePixelPermission','listOperations','listEvents', 'listWorkspaces', 'getWorkspace', 'takeControl', 'returnToAgent', 'grantOrigin', 'resolveCredential', 'finishWorkspace']);
190
190
  const pending = new Map();
191
191
  const queued = [];
192
192
  let waiting;
@@ -224,7 +224,7 @@ chrome.runtime.onMessage.addListener((message, sender, respond) => {
224
224
  const target = (await chrome.debugger.getTargets()).find(t => t.type === 'page' && t.tabId === tabId);
225
225
  if (!target || target.id !== targetId || new URL(target.url).origin !== origin)
226
226
  throw Error('adoption_page_changed');
227
- return hostRequest('offerCurrentTab', {workspaceId, targetId, origin, accountAlias});
227
+ return hostRequest('offerCurrentTab', {workspaceId, targetId, origin, accountAlias, resumeOnRestart:message.params.resumeOnRestart === true, bindOnApproval:message.params.bindOnApproval === true});
228
228
  };
229
229
  dispatch().then(result => respond({ result }), error => respond({ error: error.message }));
230
230
  return true;
@@ -9,7 +9,7 @@ export const readCapabilities = Object.freeze([
9
9
 
10
10
  export const desktopCapabilities = Object.freeze([
11
11
  'offerCurrentTab', 'listUploads', 'grantUpload', 'revokeUpload', 'respondDialog',
12
- 'listDownloads', 'cancelDownload', 'keepDownload', 'visualStatus',
12
+ 'listDownloads', 'cancelDownload', 'keepDownload', 'visualStatus','setPagePixelPermission',
13
13
  'diagnoseOperation', 'listWorkspaces', 'getWorkspace', 'takeControl',
14
14
  'returnToAgent', 'resolveCredential', 'grantOrigin', 'finishWorkspace',
15
15
  'listOperations', 'listEvents', 'eventCursor', 'listAgentHistory', 'closeWorkspace', 'showPage',