@seekskyworld/open-browser 0.2.0 → 0.3.1

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 (99) hide show
  1. package/CONTRIBUTING.md +2 -0
  2. package/Docs/desktop-packages.md +45 -0
  3. package/Docs/open-browser-api.d.ts +13 -9
  4. 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
  5. package/README.md +11 -9
  6. package/README.zh-CN.md +6 -4
  7. package/access-registry.mjs +8 -3
  8. package/action-execution.mjs +30 -5
  9. package/api-contract.mjs +8 -7
  10. package/browser-extension/_locales/en/messages.json +8 -0
  11. package/browser-extension/_locales/zh_CN/messages.json +8 -0
  12. package/browser-extension/i18n.js +84 -0
  13. package/browser-extension/manifest.json +5 -4
  14. package/browser-extension/messages.js +266 -0
  15. package/browser-extension/newtab.css +4 -0
  16. package/browser-extension/newtab.html +9 -9
  17. package/browser-extension/newtab.js +38 -35
  18. package/browser-extension/page-locale.js +23 -0
  19. package/browser-extension/phase-labels.js +33 -6
  20. package/browser-extension/popup.css +2 -2
  21. package/browser-extension/popup.html +25 -25
  22. package/browser-extension/popup.js +102 -59
  23. package/browser-extension/tab-action.js +31 -25
  24. package/browser-extension/worker.js +31 -7
  25. package/browser-extension/workspace-title.js +2 -2
  26. package/build-profile.mjs +10 -2
  27. package/capability-matrix.mjs +1 -1
  28. package/chromium-host.mjs +26 -19
  29. package/chromium-shell.mjs +7 -5
  30. package/cli.mjs +51 -48
  31. package/contract-validation.mjs +1 -1
  32. package/control.mjs +9 -8
  33. package/desktop/Info.plist +4 -2
  34. package/desktop/Launcher.m +10 -2
  35. package/desktop/OBControlBar.m +12 -8
  36. package/desktop/OBLocalization.h +20 -0
  37. package/desktop/OBPageView.m +2 -1
  38. package/desktop/WorkspacePanel.m +85 -83
  39. package/desktop/archive-release.py +5 -1
  40. package/desktop/build-macos.mjs +17 -8
  41. package/desktop/build-managed-input.mjs +2 -1
  42. package/desktop/build-portable.mjs +5 -3
  43. package/desktop/build-profile.mjs +2 -1
  44. package/desktop/build.mjs +2 -1
  45. package/desktop/create-shortcut.ps1 +7 -1
  46. package/desktop/en.lproj/Localizable.strings +106 -0
  47. package/desktop/install-menu-entry.mjs +2 -0
  48. package/desktop/notarize-macos.mjs +70 -29
  49. package/desktop/package-macos.mjs +4 -3
  50. package/desktop/sign.mjs +22 -6
  51. package/desktop/start-profile.mjs +2 -1
  52. package/desktop/start.mjs +3 -1
  53. package/desktop/verify-macos-release.mjs +27 -18
  54. package/desktop/verify-version.mjs +22 -2
  55. package/desktop/zh-Hans.lproj/Localizable.strings +106 -0
  56. package/engine-service.mjs +86 -27
  57. package/hosted/cli.mjs +2 -1
  58. package/hosted/init.mjs +2 -1
  59. package/i18n.mjs +41 -0
  60. package/managed-input.mjs +22 -5
  61. package/mcp-http.mjs +12 -11
  62. package/mcp-server.mjs +27 -10
  63. package/mcp.mjs +1 -0
  64. package/messages.zh-CN.mjs +175 -0
  65. package/package.json +9 -5
  66. package/page-activity.mjs +10 -7
  67. package/page-observation.mjs +4 -1
  68. package/paths.mjs +2 -5
  69. package/receipt-store.mjs +17 -7
  70. package/runtime.mjs +5 -4
  71. package/sdk.mjs +57 -46
  72. package/service.mjs +38 -21
  73. package/skill-links.mjs +72 -18
  74. package/skills/open-browser/SKILL.md +10 -97
  75. package/skills/open-browser/SKILL.zh-CN.md +22 -0
  76. package/skills/open-browser/references/macos.en.md +3 -0
  77. package/skills/open-browser/references/macos.md +5 -0
  78. package/skills/open-browser/references/operations.en.md +54 -0
  79. package/skills/open-browser/{SKILL.windows.md → references/operations.md} +8 -59
  80. package/skills/open-browser/references/recovery.en.md +36 -0
  81. package/skills/open-browser/references/recovery.md +38 -0
  82. package/skills/open-browser/references/windows.en.md +3 -0
  83. package/skills/open-browser/references/windows.md +5 -0
  84. package/skills/open-browser/scripts/bootstrap.mjs +80 -90
  85. package/skills/open-browser/scripts/guide.mjs +20 -0
  86. package/skills/open-browser/scripts/open-browser +5 -1
  87. package/studio/demo-site.mjs +5 -4
  88. package/studio/index.html +37 -33
  89. package/studio/index.mjs +10 -3
  90. package/studio/native-demo.mjs +8 -7
  91. package/studio/studio.css +3 -0
  92. package/studio/studio.js +99 -69
  93. package/system-i18n.mjs +19 -0
  94. package/tab-adoption.mjs +9 -3
  95. package/tab-recovery.mjs +100 -0
  96. package/visual-page.mjs +17 -7
  97. package/workspace-lifecycle.mjs +18 -2
  98. package/workspace-state.mjs +57 -16
  99. package/skills/open-browser/SKILL.macos.md +0 -112
package/sdk.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { t } from "./i18n.mjs";
1
2
  import { readFile } from 'node:fs/promises';
2
3
  import { Agent, request } from 'node:http';
3
4
  import { randomUUID } from 'node:crypto';
@@ -11,34 +12,37 @@ export { agentMethods };
11
12
  * service error. The hint never replaces the server error message.
12
13
  */
13
14
  export const recoveryHints = Object.freeze({
14
- SERVICE_UNAVAILABLE: '启动 open-browser 后重试同一只读请求。',
15
- TASK_NAME_REQUIRED: '为 createWorkspace 或 open 提供清晰的非空 name,再重新创建任务。',
16
- REQUEST_TIMEOUT: '用同一 operationId 查询 getOperation 或 diagnoseOperation,再决定是否继续。',
17
- stale_ref: '重新 observe 当前页面并用新 ref 构造动作。',
18
- stale_document: '重新 observe 当前页面后再执行动作。',
19
- stale_control: '重新 observe 获取最新 controlGeneration。',
20
- stale_observation: '重新 observe 当前页面,不要复用旧文档标识。',
21
- target_obscured: '重新 observe 并等待遮罩消失,再用新的 operationId 重试。',
22
- target_ambiguous: '用 observe 的 locator 或 within 缩小目标范围。',
23
- target_missing: '重新 observe 并核对页面状态或目标名称。',
24
- navigation_failed: '先 observe 当前页面和地址,再决定是否重试导航。',
25
- origin_denied: '核对 blockedOrigins,取得控制权后用 grantOrigin 授权所需来源。',
26
- profile_mismatch: '请切换至该标签页所在的 open-browser profile。',
27
- adoption_expired: '请用户在原标签页重新签发授权,使用所选任务的 workspaceId 兑换。',
28
- adoption_page_changed: '请用户核对当前标签和站点,再授权此页。',
29
- adoption_requires_empty_workspace: '创建新的命名工作区,再让用户选择该任务。',
30
- adoption_requires_private_workspace: '创建一个仅当前 Agent 使用的新任务后重新授权。',
31
- sync_pending: '扩展尚未确认该页。请读取 getWorkspace 后重试 reattachPage。',
32
- single_tab_scope: '此授权覆盖用户所选的一页及其站点。其他页需要单独授权。',
33
- page_not_found: '用 getRecoverySummary 核对原页状态,需要时请用户重新选择标签。',
34
- workspace_not_found: '核对 profileId。服务重启后用 getRecoverySummary 查历史,并请用户重新授权原页。',
35
- finish_preview_changed: '等待当前操作完成,重新调用 previewFinish 核对页面清单。',
36
- input_guard_unavailable: '请检查 Dev Chromium 是否包含受管页面输入保护补丁。',
37
- workspace_under_user_control: '等待用户交回 Agent 控制权后重新 observe。',
38
- outcome_unknown: '先用 getOperation 或 diagnoseOperation,并核对站点结果后再重试。',
39
- inspect_before_retry: '先核对站点是否已生效,再决定是否提交新的 operationId。',
40
- run_timeout: '运行预算已耗尽。用同一 operationId 查询回执,并核对站点结果后再决定是否继续。',
41
- invalid_params: '运行 --schema 或读取 capabilities,按当前契约修正参数。',
15
+ SERVICE_UNAVAILABLE: t("The request did not reach the service. Start Open Browser and check the local connection credentials before retrying."),
16
+ RESPONSE_LOST: t("After creating a task, check listWorkspaces. For an existing workspace, check getWorkspace. If there is an operationId, check getOperation. You can repeat reads."),
17
+ TASK_NAME_REQUIRED: t("Give createWorkspace or open a clear, non-empty name, then create the task again."),
18
+ REQUEST_TIMEOUT: t("Check getOperation or diagnoseOperation with the same operationId before continuing."),
19
+ stale_ref: t("Observe the page again and use the new ref for your action."),
20
+ stale_document: t("Observe the current page again before acting."),
21
+ stale_control: t("Call observe again for the current controlGeneration."),
22
+ stale_observation: t("Observe the current page again to get its new document ID."),
23
+ target_obscured: t("Check the receipt's obstruction and the foreground dialog in the current observation. Wait for it to clear before acting."),
24
+ pixel_permission_required: t("Ask the user to allow screenshots for the task owner in the tab extension. An administrator can grant a delegated client access by principalId and origin."),
25
+ stale_visual_frame: t("Capture the stable target region again and act before the new frame expires."),
26
+ target_ambiguous: t("Narrow the target with the observe locator or within."),
27
+ target_missing: t("Observe again and verify the page state or target name."),
28
+ navigation_failed: t("Observe the current page and its URL before retrying navigation."),
29
+ origin_denied: t("Check blockedOrigins. Once in control, grant the required origin with grantOrigin."),
30
+ profile_mismatch: t("Switch to the Open Browser profile that owns the tab."),
31
+ adoption_expired: t("Ask the user to authorize the original tab again, then redeem the authorization with the selected workspaceId."),
32
+ adoption_page_changed: t("Ask the user to check the tab and site, then authorize the page again."),
33
+ adoption_requires_empty_workspace: t("Create a new, named, empty workspace and select the tab again."),
34
+ adoption_requires_private_workspace: t("Create a private workspace for this agent and authorize the tab again."),
35
+ sync_pending: t("The extension has not confirmed the page yet. Read getWorkspace and retry reattachPage."),
36
+ single_tab_scope: t("This grant covers the selected tab and its site. Authorize any other page separately."),
37
+ page_not_found: t("Check the original page with getRecoverySummary. Ask the user to select the tab again if needed."),
38
+ workspace_not_found: t("Check profileId. After a restart, read getRecoverySummary and ask the user to authorize the original tab if needed."),
39
+ finish_preview_changed: t("Wait for the current operation to finish, then run previewFinish again."),
40
+ input_guard_unavailable: t("Check whether the development Chromium build includes the native managed input guard."),
41
+ workspace_under_user_control: t("Call reattachPage with the original page handle and waitMs to wait for control and a fresh observation."),
42
+ outcome_unknown: t("Check getOperation or diagnoseOperation and verify the site before retrying."),
43
+ inspect_before_retry: t("Check whether the site already applied the action before submitting a new operationId."),
44
+ run_timeout: t("The operation timed out. Query the receipt with the same operationId and check the site before continuing."),
45
+ invalid_params: t("Run --schema or read capabilities for the accepted parameters."),
42
46
  });
43
47
 
44
48
  export class OpenBrowserError extends Error {
@@ -50,7 +54,8 @@ export class OpenBrowserError extends Error {
50
54
  }
51
55
  }
52
56
 
53
- const unavailable = () => new OpenBrowserError('SERVICE_UNAVAILABLE', '请先启动 open-browser 本地服务。');
57
+ const unavailable = () => new OpenBrowserError('SERVICE_UNAVAILABLE', t("Start the local Open Browser service."));
58
+ const responseLost = () => new OpenBrowserError('RESPONSE_LOST', t("The connection closed before a response arrived. Check the request outcome."));
54
59
 
55
60
  export class OpenBrowserClient {
56
61
  constructor(options = {}) {
@@ -63,20 +68,20 @@ export class OpenBrowserClient {
63
68
  (codex ? 'Codex' : options.fallbackName ?? 'SDK'));
64
69
  }
65
70
 
66
- async call(method, params = {}) {
71
+ async call(method, params = {}, {signal} = {}) {
67
72
  if (!agentMethods.includes(method))
68
- throw new OpenBrowserError('UNKNOWN_METHOD', '未知的 Agent API 方法。');
73
+ throw new OpenBrowserError('UNKNOWN_METHOD', t("Unknown agent API method."));
69
74
  if (!params || typeof params !== 'object' || Array.isArray(params))
70
- throw new OpenBrowserError('INVALID_PARAMS', '参数必须是 JSON 对象。');
75
+ throw new OpenBrowserError('INVALID_PARAMS', t("Parameters must be a JSON object."));
71
76
  if (['createWorkspace', 'open'].includes(method) &&
72
77
  (typeof params.name !== 'string' || !params.name.trim()))
73
- throw new OpenBrowserError('TASK_NAME_REQUIRED', '创建 Agent 任务时必须提供非空任务名称 name。');
78
+ throw new OpenBrowserError('TASK_NAME_REQUIRED', t("Supply a non-empty task name when creating an agent workspace."));
74
79
  if (['createWorkspace','open'].includes(method) && params.agentName === undefined)
75
80
  params = { ...params, agentName: this.agentName };
76
- return localRequest(this.socketPath,this.tokenPath,'/v1/call',method,params,this.agent);
81
+ return localRequest(this.socketPath,this.tokenPath,'/v1/call',method,params,this.agent,signal);
77
82
  }
78
- async capabilities() {
79
- try { return await this.call('capabilities'); }
83
+ async capabilities(options) {
84
+ try { return await this.call('capabilities', {}, options); }
80
85
  catch(error) {
81
86
  if (['UNKNOWN_METHOD','unknown_method','forbidden'].includes(error.code)) return {version:0,visual:{enabled:false,actions:[]}};
82
87
  throw error;
@@ -117,7 +122,7 @@ export class OpenBrowserClient {
117
122
  observeAndAct(page, request = {}) {
118
123
  const { actions, observeAfter, timeoutMs, operationId = randomUUID(), ...observeOptions } = request;
119
124
  if (!Array.isArray(actions) || actions.length === 0)
120
- return Promise.reject(new OpenBrowserError('INVALID_PARAMS', 'observeAndAct 需要至少一个 action。'));
125
+ return Promise.reject(new OpenBrowserError('INVALID_PARAMS', t("observeAndAct requires at least one action.")));
121
126
  return this.call('observeAndAct', {
122
127
  ...page, ...observeOptions, actions, observeAfter, timeoutMs, operationId,
123
128
  });
@@ -135,8 +140,8 @@ export class OpenBrowserClient {
135
140
  runWorkflow(page, request) { return this.call('runWorkflow',{...request,...page}); }
136
141
  act(page, operation) { return this.call('act', { ...operation, ...page }); }
137
142
  diagnoseOperation(workspaceId, operationId) { return this.call('diagnoseOperation', {workspaceId, operationId}); }
138
- getOperation(workspaceId, operationId) {
139
- return this.call('getOperation', { workspaceId, operationId });
143
+ getOperation(workspaceId, operationId, {waitMs} = {}) {
144
+ return this.call('getOperation', { workspaceId, operationId, ...(waitMs !== undefined && {waitMs}) });
140
145
  }
141
146
  cancelOperation(workspaceId, operationId) {
142
147
  return this.call('cancelOperation', { workspaceId, operationId });
@@ -146,12 +151,13 @@ export class OpenBrowserClient {
146
151
  close() { this.agent.destroy(); }
147
152
  }
148
153
 
149
- export async function localRequest(socket, credentials, endpoint, method, params, agent) {
154
+ export async function localRequest(socket, credentials, endpoint, method, params, agent, signal) {
150
155
  const body = JSON.stringify({ method, params });
151
156
  let token;
152
157
  try {
153
- token = (await readFile(credentials, 'utf8')).trim();
158
+ token = (await readFile(credentials, {encoding:'utf8', signal})).trim();
154
159
  } catch {
160
+ signal?.throwIfAborted();
155
161
  throw unavailable();
156
162
  }
157
163
  if (!token) throw unavailable();
@@ -165,12 +171,12 @@ export async function localRequest(socket, credentials, endpoint, method, params
165
171
  'content-type': 'application/json',
166
172
  'content-length': Buffer.byteLength(body),
167
173
  },
168
- agent,
174
+ agent, signal,
169
175
  }, res => {
170
176
  let data = '';
171
177
  res.setEncoding('utf8');
172
178
  res.on('data', chunk => { data += chunk; });
173
- res.on('error', () => reject(unavailable()));
179
+ res.once('error', () => reject(signal?.aborted ? signal.reason : responseLost()));
174
180
  res.on('end', () => {
175
181
  let reply;
176
182
  try { reply = JSON.parse(data); } catch {}
@@ -179,13 +185,18 @@ export async function localRequest(socket, credentials, endpoint, method, params
179
185
  } else if (res.statusCode === 200 && reply && Object.hasOwn(reply, 'result')) {
180
186
  resolve(reply.result);
181
187
  } else {
182
- reject(new OpenBrowserError('INVALID_RESPONSE', '本地服务返回了无法识别的响应。'));
188
+ reject(new OpenBrowserError('INVALID_RESPONSE', t("The local service returned an unrecognized response.")));
183
189
  }
184
190
  });
185
191
  });
186
- req.once('error', () => reject(unavailable()));
192
+ // A failed connect cannot have delivered the request. A reset on an
193
+ // established (including reused) socket can follow a committed write.
194
+ req.once('error', error => {
195
+ if (signal?.aborted) reject(signal.reason);
196
+ else reject(error.syscall === 'connect' ? unavailable() : responseLost());
197
+ });
187
198
  req.setTimeout(limits.clientTimeoutMs, () => {
188
- reject(new OpenBrowserError('REQUEST_TIMEOUT', '等待服务响应超时。对于已派发的动作,请按 operationId 查询回执。'));
199
+ reject(new OpenBrowserError('REQUEST_TIMEOUT', t("Timed out waiting for the service. Look up dispatched actions by operationId.")));
189
200
  req.destroy();
190
201
  });
191
202
  req.end(body);
package/service.mjs CHANGED
@@ -1,15 +1,20 @@
1
+ import { locale } from './i18n.mjs';
1
2
  import { limits } from './api-contract.mjs';
2
3
  import path from 'node:path';
4
+ import { TabRecovery, restoreApprovedTabs } from './tab-recovery.mjs';
3
5
  import { AccessRegistry } from './access-registry.mjs';
4
6
  import http from 'node:http';
5
7
  import net from 'node:net';
6
8
  import { createInterface } from 'node:readline';
9
+ import { setTimeout as delay } from 'node:timers/promises';
7
10
  import { randomBytes, timingSafeEqual } from 'node:crypto';
8
11
  import { chmod, lstat, mkdir, readFile, rename, unlink, writeFile } from 'node:fs/promises';
9
12
  import { pathToFileURL } from 'node:url';
10
13
  import { launchBrowser } from './control.mjs';
11
14
  import { agentMethods } from './sdk.mjs';
12
15
  import { BrowserService } from './engine-service.mjs';
16
+ import { desktopWorkspaces, workspaceSyncView } from './workspace-state.mjs';
17
+ import { autoInstallSkillLinks } from './skill-links.mjs';
13
18
  import { socketPath, stateDir, tokenPath, adminTokenPath, pidPath } from './paths.mjs';
14
19
 
15
20
  function listen(server) {
@@ -71,15 +76,7 @@ function errorCode(error) {
71
76
  export async function startApplication({ headless = false, mode = 'service', onShow, onBar,
72
77
  launchServiceBrowser = launchBrowser, readOnlyObserver, chromiumNetLog } = {}) {
73
78
  if (!['web', 'native', 'service', 'chromium'].includes(mode)) throw new Error('invalid_mode');
74
- if (process.env.OPEN_BROWSER_AUTO_INSTALL_SKILLS !== '0') {
75
- try {
76
- const { installAgentSkillLinks } = await import('./skill-links.mjs');
77
- const result = await installAgentSkillLinks();
78
- if (process.env.OPEN_BROWSER_SKILLS_VERBOSE === '1') console.error(JSON.stringify({ skillLinks: result }));
79
- } catch (error) {
80
- if (process.env.OPEN_BROWSER_SKILLS_VERBOSE === '1') console.error(JSON.stringify({ skillLinksError: error.message }));
81
- }
82
- }
79
+ await autoInstallSkillLinks();
83
80
  await mkdir(stateDir, { mode: 0o700, recursive: true });
84
81
  if (process.platform !== 'win32') await chmod(stateDir, 0o700);
85
82
  const token = randomBytes(32).toString('hex');
@@ -159,7 +156,10 @@ export async function startApplication({ headless = false, mode = 'service', onS
159
156
  server.closeAllConnections();
160
157
  try {
161
158
  if (studio) await studio.close();
162
- if (engine) await engine.shutdown();
159
+ if (engine) {
160
+ if (engine.tabRecovery) engine.tabRecovery.closed = true;
161
+ await engine.shutdown();
162
+ }
163
163
  } finally {
164
164
  await sharedContext?.close().catch(() => {});
165
165
  await browser?.close().catch(() => {});
@@ -175,26 +175,36 @@ export async function startApplication({ headless = false, mode = 'service', onS
175
175
  if (mode === 'chromium') {
176
176
  const { launchChromiumShell } = await import('./chromium-shell.mjs');
177
177
  const { chromiumHost } = await import('./chromium-host.mjs');
178
- sharedContext = await launchChromiumShell({ headless, netLogPath:chromiumNetLog });
178
+ const restoreSession = !!registry.db.prepare('SELECT 1 FROM resumable_tabs WHERE expires>? LIMIT 1').get(Date.now());
179
+ const launch = async () => {
180
+ // After SIGKILL the old browser can still be closing its profile.
181
+ const deadline = Date.now() + 5000;
182
+ for (;;) {
183
+ try { return await launchChromiumShell({headless,netLogPath:chromiumNetLog,restoreSession}); }
184
+ catch (error) {
185
+ if (Date.now() >= deadline || !/ProcessSingleton|SingletonLock|user data directory is already in use/i.test(error.message)) throw error;
186
+ await delay(200);
187
+ }
188
+ }
189
+ };
190
+ sharedContext = await launch();
179
191
  try { shell = await chromiumHost(sharedContext); }
180
192
  catch (error) {
181
193
  if (error.code !== 'extension_reload') throw error;
182
194
  await sharedContext.close();
183
- sharedContext = await launchChromiumShell({ headless, netLogPath:chromiumNetLog });
195
+ sharedContext = await launch();
184
196
  shell = await chromiumHost(sharedContext);
185
197
  }
186
198
  browser = sharedContext.browser();
187
199
  } else {
188
200
  browser = await launchServiceBrowser({ headless: mode === 'native' || headless });
189
201
  }
190
- engine = new BrowserService(browser, { concurrency: 4, sharedContext, readOnlyObserver, journalPath: path.join(stateDir, 'open-browser-receipts.sqlite'), releaseTab: shell?.releaseTab, setInputGuard: shell?.setInputGuard, withAgentInput: shell?.withAgentInput, inputGuardMode: shell?.inputGuardMode, groupTab: shell?.groupTab, onActivity: shell?.onActivity,
202
+ engine = new BrowserService(browser, { concurrency: 4, sharedContext, tabRecovery:sharedContext && new TabRecovery(registry), readOnlyObserver, journalPath: path.join(stateDir, 'open-browser-receipts.sqlite'), releaseTab: shell?.releaseTab, setInputGuard: shell?.setInputGuard, withAgentInput: shell?.withAgentInput, inputGuardMode: shell?.inputGuardMode, groupTab: shell?.groupTab, onActivity: shell?.onActivity,
191
203
  onActionTarget: shell?.onActionTarget });
204
+ if (sharedContext) await restoreApprovedTabs(engine, registry);
192
205
  const call = async (method, params = {}) => {
193
206
  if (method === 'createWorkspace') return registry.call(engine, 'local', method, params);
194
- if (method === 'listWorkspaces') {
195
- const owners = new Set([...engine.workspaces.values()].map(ws => ws.owner));
196
- return (await Promise.all([...owners].map(owner => engine.call(method, params, owner)))).flat();
197
- }
207
+ if (method === 'listWorkspaces') return desktopWorkspaces(engine.workspaces);
198
208
  return engine.call(method === 'finishWorkspace' ? 'hostFinishWorkspace' : method, params, registry.owner(params.workspaceId) || 'local', 'desktop');
199
209
  };
200
210
  if (mode === 'web') {
@@ -211,9 +221,16 @@ export async function startApplication({ headless = false, mode = 'service', onS
211
221
  if (!ready) throw Object.assign(new Error('not_ready'), { code: 'not_ready' });
212
222
  switch (method) {
213
223
  case 'listWorkspaces': return call(method, params);
214
- case 'offerCurrentTab':
224
+ case 'offerCurrentTab': {
215
225
  if (registry.hasDelegates(params.workspaceId)) throw Object.assign(new Error(), {code:'adoption_requires_private_workspace'});
216
- return call(method, params);
226
+ const offer = await call(method, params);
227
+ if (params.bindOnApproval !== true) return offer;
228
+ const owner = registry.owner(offer.workspaceId);
229
+ if (!owner) throw Object.assign(new Error(), {code:'workspace_not_found'});
230
+ return registry.call(engine, owner, 'adoptCurrentTab', {
231
+ workspaceId:offer.workspaceId, adoptionToken:offer.adoptionToken
232
+ });
233
+ }
217
234
  case 'listAgentHistory': return registry.listHistory(engine, 'local', params);
218
235
  case 'getWorkspace': return call(method, params);
219
236
  default: return call(method, params);
@@ -229,7 +246,7 @@ export async function startApplication({ headless = false, mode = 'service', onS
229
246
  await rename(temporaryPid, pidPath);
230
247
  pidWritten = true;
231
248
  ready = true;
232
- shell?.start(hostCall, onBar);
249
+ shell?.start(hostCall, onBar, () => desktopWorkspaces(engine.workspaces, workspaceSyncView));
233
250
  browser.once('disconnected', () => { void close(); });
234
251
  return { close, closed, openControlWindow, studio, page, hostCall, sharedContext,
235
252
  clickBar: frame => shell?.clickBar(frame, hostCall) };
@@ -247,7 +264,7 @@ async function main() {
247
264
  const send = frame => process.stdout.write(JSON.stringify(frame) + '\n');
248
265
  const app = await startApplication({ headless: process.argv.includes('--headless'),
249
266
  mode: native ? 'native' : process.argv.includes('--chromium') ? 'chromium' : 'service',
250
- onBar: desktopBar ? bar => send({ event: 'desktop.bar', bar }) : undefined,
267
+ onBar: desktopBar ? bar => send({ event: 'desktop.bar', bar, locale }) : undefined,
251
268
  onShow: () => send({ event: 'desktop.open' }) });
252
269
  active = app;
253
270
  for (const signal of ['SIGINT', 'SIGTERM']) process.once(signal, () => { void app.close(); });
package/skill-links.mjs CHANGED
@@ -1,7 +1,9 @@
1
- import { lstat, mkdir, realpath, symlink, unlink } from 'node:fs/promises';
1
+ import { lstat, mkdir, readFile, realpath, rename, rm, stat, symlink, unlink, writeFile } from 'node:fs/promises';
2
+ import { randomUUID } from 'node:crypto';
2
3
  import os from 'node:os';
3
4
  import path from 'node:path';
4
5
  import { fileURLToPath, pathToFileURL } from 'node:url';
6
+ import { stateDir } from './paths.mjs';
5
7
 
6
8
  const sourceRoot = path.dirname(fileURLToPath(import.meta.url));
7
9
  const defaultSkillSource = path.join(sourceRoot, 'skills', 'open-browser');
@@ -33,38 +35,61 @@ function configuredRoots() {
33
35
 
34
36
  async function isDirectory(pathname) {
35
37
  try {
36
- return (await lstat(pathname)).isDirectory();
38
+ return (await stat(pathname)).isDirectory();
37
39
  } catch {
38
40
  return false;
39
41
  }
40
42
  }
41
43
 
44
+ async function createDirectoryLink(source, relativeSource, link) {
45
+ try {
46
+ await symlink(relativeSource, link, 'dir');
47
+ } catch (error) {
48
+ if (process.platform !== 'win32' || error.code !== 'EPERM') throw error;
49
+ await symlink(source, link, 'junction');
50
+ }
51
+ }
52
+
42
53
  async function linkSkill(root, source) {
43
54
  const link = path.join(root, 'open-browser');
44
- const relativeSource = path.relative(root, source) || '.';
55
+ await mkdir(root, { recursive: true });
56
+ const relativeSource = path.relative(await realpath(root), source) || '.';
45
57
  try {
46
- const entry = await lstat(link);
47
- if (!entry.isSymbolicLink()) return { status: 'skipped_conflict', path: link };
48
- try {
49
- const current = await realpath(link);
50
- if (current === source) return { status: 'existing', path: link };
51
- } catch {
52
- // Replace a broken open-browser link with the current source.
53
- }
54
- await unlink(link);
55
- await symlink(relativeSource, link, 'dir');
58
+ await createDirectoryLink(source, relativeSource, link);
56
59
  return { status: 'linked', path: link };
57
60
  } catch (error) {
58
- if (error.code !== 'ENOENT') return { status: 'skipped_error', path: link, code: error.code };
59
- await mkdir(root, { recursive: true });
60
- await symlink(relativeSource, link, 'dir');
61
- return { status: 'linked', path: link };
61
+ if (error.code !== 'EEXIST') throw error;
62
+ }
63
+ if (!(await lstat(link)).isSymbolicLink()) return { status: 'skipped_conflict', path: link };
64
+ const current = await realpath(link).catch(error => {
65
+ if (error.code !== 'ENOENT') throw error;
66
+ });
67
+ if (current === source) return { status: 'existing', path: link };
68
+ if (current) {
69
+ const manifest = await readFile(path.resolve(current, '../../package.json'), 'utf8').then(JSON.parse).catch(() => null);
70
+ if (path.basename(current) !== 'open-browser' || path.basename(path.dirname(current)) !== 'skills' ||
71
+ manifest?.name !== '@seekskyworld/open-browser') return { status: 'skipped_conflict', path: link };
72
+ }
73
+ const temporary = link + '.' + randomUUID();
74
+ await createDirectoryLink(source, relativeSource, temporary);
75
+ try {
76
+ // Windows cannot replace a directory symlink with a rename. Prepare the
77
+ // replacement first and accept a concurrent scan that installed it.
78
+ if (process.platform === 'win32') await unlink(link).catch(error => { if (error.code !== 'ENOENT') throw error; });
79
+ try { await rename(temporary, link); }
80
+ catch (error) {
81
+ if (await realpath(link).catch(() => null) !== source) throw error;
82
+ }
83
+ } finally {
84
+ await rm(temporary, { force: true });
62
85
  }
86
+ return { status: 'linked', path: link };
63
87
  }
64
88
 
65
89
  export async function installAgentSkillLinks({ source = defaultSkillSource } = {}) {
66
- if (process.env.OPEN_BROWSER_AUTO_INSTALL_SKILLS === '0') return { disabled: true, links: [] };
90
+ if (process.env.NODE_TEST_CONTEXT || process.env.OPEN_BROWSER_AUTO_INSTALL_SKILLS === '0') return { disabled: true, links: [] };
67
91
  if (!(await isDirectory(source))) return { disabled: false, links: [], sourceMissing: true };
92
+ source = await realpath(source);
68
93
  const links = [];
69
94
  const seen = new Set();
70
95
  for (const agent of configuredRoots()) {
@@ -80,6 +105,35 @@ export async function installAgentSkillLinks({ source = defaultSkillSource } = {
80
105
  return { disabled: false, links, source: path.resolve(source) };
81
106
  }
82
107
 
108
+ // Desktop starts always discover new agents. Short-lived Skill commands
109
+ // share a recent successful scan across processes using this profile.
110
+ export async function autoInstallSkillLinks({ useCache = false } = {}) {
111
+ if (process.env.NODE_TEST_CONTEXT || process.env.OPEN_BROWSER_AUTO_INSTALL_SKILLS === '0') return;
112
+ const verbose = process.env.OPEN_BROWSER_SKILLS_VERBOSE === '1';
113
+ try {
114
+ const marker = path.join(stateDir, 'skill-links.json');
115
+ const key = JSON.stringify([defaultSkillSource, ...configuredRoots().map(agent => agent.root)]);
116
+ if (useCache) {
117
+ const saved = await readFile(marker, 'utf8').then(JSON.parse).catch(() => null);
118
+ const age = Date.now() - saved?.checkedAt;
119
+ if (saved?.key === key && age >= 0 && age < 10 * 60_000) return;
120
+ }
121
+ const result = await installAgentSkillLinks();
122
+ if (verbose) console.error(JSON.stringify({ skillLinks: result }));
123
+ if (result.sourceMissing || result.links.some(link => link.status === 'skipped_error')) return;
124
+ await mkdir(stateDir, { recursive: true, mode: 0o700 });
125
+ const temporary = marker + '.' + randomUUID();
126
+ try {
127
+ await writeFile(temporary, JSON.stringify({ key, checkedAt: Date.now() }), { mode: 0o600, flag: 'wx' });
128
+ await rename(temporary, marker);
129
+ } finally {
130
+ await rm(temporary, { force: true });
131
+ }
132
+ } catch (error) {
133
+ if (verbose) console.error(JSON.stringify({ skillLinksError: error.message }));
134
+ }
135
+ }
136
+
83
137
  if (process.argv[1] && pathToFileURL(process.argv[1]).href === import.meta.url) {
84
138
  installAgentSkillLinks().then(result => {
85
139
  process.stdout.write(JSON.stringify(result) + '\n');
@@ -1,107 +1,20 @@
1
1
  ---
2
2
  name: open-browser
3
- description: 用户要求用 open-browser 浏览、观察页面、操作工作区或验证登录时,通过 open-browser CLI 控制其独立 Chromium。
3
+ description: Use the Open Browser CLI to browse, observe pages, operate workspaces or verify sign-in when the user requests Open Browser. 使用 open-browser 操作浏览器工作区或验证登录。
4
4
  ---
5
5
 
6
- 在 macOS 和 Linux 使用本 Skill 目录内的 `scripts/open-browser`,在 Windows 使用 `scripts/open-browser.cmd`。便携包中的 Skill 位于 `app/skills/open-browser/`,其启动脚本使用包内 Node。下文以 `$ob` 表示它的绝对路径。命令名是第一个参数,其余参数从标准输入读取 JSON,标准输出也是 JSON。运行 `"$ob" --help` 查看方法。首次调用会探测本机服务,必要时自动启动 open-browser 应用或便携包并等待就绪后重试一次。设置 `OPEN_BROWSER_AUTOSTART=0` 可关闭自动启动。该引导只使用本机 socket 或命名管道,不需要配置 MCP 地址。连续任务可运行 `"$ob" session`,它按行读取 `{\"id\":1,\"method\":\"observe\",\"params\":{...}}`,复用同一个 Node 客户端直到标准输入关闭。
6
+ [简体中文](SKILL.zh-CN.md)
7
7
 
8
- 运行 `open-browser skill` 可以输出当前安装包对应平台的完整指南,不会启动服务。需要 URL 形式 MCP 配置时使用 `open-browser-mcp-http`,它只监听回环地址并要求 profile token 的 Bearer 认证。
8
+ ## Start from the current task
9
9
 
10
- ## Agent 控制时的输入保护
10
+ 1. **Continue an existing page.** Get the page handle with `getWorkspace`, or find the task using `listWorkspaces`. Call `reattachPage` for a fresh observation. To use an ordinary signed-in tab, create a named, empty workspace and save `eventCursor.nextCursor`. Ask the user to select the task in the tab’s extension and click **Give this tab to the agent**. Call `waitForEvent` with `workspaceId`, `kind:"page_bound"` and `after`, then use the event’s `pageId` with `reattachPage`. A timed-out wait can resume from the same cursor.
11
+ 2. **Open a new page.** Call `open` with a clear task `name` and a specific `url`. Save the workspace and page IDs and call `observe`. Use `openPage` to add a page to an existing task. Parallel agents can supply their own `agentName`.
12
+ 3. **Resume after human control.** Call `handOff` for the user to handle sign-in or a dialog. Call `reattachPage` with the original handle and `waitMs:30000`. When the user clicks **Return to agent**, use the observation in the response. Workspace `mode` describes ownership. Page `readyForAgent` indicates whether the page is ready for input.
11
13
 
12
- 工作区进入 `agent` 状态后,受管页面的内容区域会强制锁定人工鼠标、触控板和键盘输入。Agent 的每个写入动作在服务端打开一次短暂的派发窗口,动作结束后立即重新锁定。地址栏、标签栏和工作区控制条仍可使用。页面底部的 **人工接管** 是唯一的人工输入入口,接管完成后页面会显示 **交回 Agent**。
14
+ ## Act on the page
13
15
 
14
- `getWorkspace` 的 `security.inputGuard` 会报告 `native` 或 `fallback`。`native` 使用带有 open-browser 输入补丁的 Chromium,`fallback` 使用受管页面的捕获层并保持相同的接管状态机。没有该补丁的 Dev 构建可启用 `fallback`。只有明确设置 `OPEN_BROWSER_INPUT_GUARD=off` 才会关闭保护,适合诊断场景。Agent 操作期间不要继续使用旧的人工输入结果,交回后先重新 `observe`。
16
+ Use this skill’s `scripts/open-browser` on macOS and Linux, or `scripts/open-browser.cmd` on Windows. The launcher discovers the local service and starts the app when needed. For a sequence of calls, reuse an SDK client or run the launcher's `session` command and send one request per line, such as `{"id":1,"method":"listWorkspaces","params":{}}`.
15
17
 
16
- ## 选择入口
18
+ Pass control refs from the latest observation to `observeAndAct` with a unique `operationId`, the `actions`, `observeAfter:"delta"` and `waitMs:3000`. Read the changes from the completed receipt. If it is still queued or running, use the same ID with `getOperation` and a bounded `waitMs` of up to 10000. For `outcome_unknown`, verify the result on the site before retrying. Use a workspace-bound `credentialRef` for passwords. Before reporting completion, call `finishWorkspace` and select the result pages in `keepPageIds`.
17
19
 
18
- | 场景 | 调用顺序 |
19
- | --- | --- |
20
- | 已登录的 open-browser 普通标签页 | 先用 `createWorkspace` 建立命名任务。请用户在原页打开扩展,选择该任务,点击「让 Agent 操作此页」,将授权框内的 JSON 交给你。在两分钟内原样传给 `adoptCurrentTab`,再用返回的句柄 `observe`。 |
21
- | 新开页面 | 用 `open` 传任务名和 URL,再 `observe`。 |
22
- | 用户接管后交回 | 用保存的 workspaceId 和 pageId 调用 `reattachPage`,可传 `waitMs:30000` 等待用户点击「交回 Agent」,交回后自动核对原页并返回新的观察。原页已关闭时请用户重新选择。 |
23
- | 登录资料或服务发生变化 | 核对工作区的 `profileId`、站点和用户填写的账号别名。服务重启后用 `getRecoverySummary` 查看历史,再请用户在正确资料内重新授权。 |
24
-
25
- 单页授权绑定当前任务和站点。任务结束时原页自动保留。用 `previewFinish` 核对 `keptPageIds` 和 `closedPageIds`,将返回的 `previewId` 及原选择传入 `finishWorkspace`。遇到 `finish_preview_changed` 时重新预览。
26
-
27
- 对于 React Flow 画布或带消息角色标记的聊天区,`canvasSnapshot` 返回已渲染的节点、边、消息和下载链接标签。操作后可再读一次核对结果,`snapshotVersion` 随快照内容或控制代次变化。返回 `unsupported` 时使用普通观察或已授权的画面。
28
-
29
- ## 最短路径
30
-
31
- 一次性打开并读取页面时,优先使用 `open`,它会创建工作区、打开明确网址并返回页面句柄。随后把句柄传给 `observe`,再把最新观察中的 `documentId` 和 `controlGeneration` 传给 `act`。任务完成后调用 `finishWorkspace`,将需要交付的页面放进 `keepPageIds`。
32
-
33
- ```sh
34
- ob="$PWD/skills/open-browser/scripts/open-browser"
35
- page=$(printf '%s\n' '{"url":"https://example.org","name":"页面检查"}' | "$ob" open)
36
- printf '%s\n' "$page"
37
- # 从上一个 JSON 结果取 workspaceId 和 pageId,再执行 observe
38
- printf '%s\n' '{"workspaceId":"WORKSPACE_ID","pageId":"PAGE_ID"}' | "$ob" observe
39
- ```
40
-
41
- 多步骤任务使用 `createWorkspace` 和 `openPage`,因为它们允许你明确设置 `allowedOrigins` 与 `resourceOrigins`。调用 `capabilities` 可先查看当前服务版本、限额、隐私模式及可用视觉动作。
42
-
43
- 遇到错误时按返回的 `code` 和 `nextAction` 处理。`stale_ref`、`stale_document`、`stale_control` 和 `stale_observation` 先重新 `observe`。`target_ambiguous` 用 `observe.locator` 缩小范围。`target_obscured` 等待遮罩消失后用新的操作号重试。`origin_denied` 先核对 `blockedOrigins`,取得工作区控制权后再用 `grantOrigin`。`human_verification_required` 表示站点要求安全验证,停止重试,调用 `handOff`,让用户在可见页面完成验证后再调用 `returnToAgent` 并重新 `observe`。`REQUEST_TIMEOUT`、`run_timeout`、`outcome_unknown` 或 `inspect_before_retry` 先用同一个 `operationId` 查询回执并核对站点结果。
44
-
45
- 若只使用 SDK,可用 `openAndObserve` 省去首次句柄拼接,用 `observeAndAct` 或 `actAfterObserve` 在一次服务请求中完成最新观察和动作提交,用 `finish` 自动生成交付操作号。这些辅助方法仍执行服务端的工作区权限、来源和过期引用检查。连续任务优先复用同一个 SDK 客户端,避免每个动作重新启动 CLI。
46
-
47
- 1. 运行 `"$ob" listWorkspaces </dev/null`。继续已有任务时使用该任务的工作区。新任务通过 `createWorkspace` 创建,必须填写清晰的 `name` 任务名称,并保存返回的 `workspaceId`。`name` 填任务名称,`agentName` 填创建者的显示名(最多 80 个 Unicode 码点)。多个子代理并行时,每个子代理须显式传自己的名字。同一客户端的子代理通常共享环境或 MCP 握手,只能由子代理自身区分身份。
48
- 2. 调用 `openPage`,传入 `workspaceId` 和目标 `url`,保存返回的页面句柄。把完整句柄传给 `observe`,读取可见文本、元素的 `role/name/ref`、`documentId` 和 `controlGeneration`。
49
- 3. 调用 `act`,把页面句柄、刚取得的两个代次标识、唯一 `operationId` 和有序的 `actions` 放入同一个 JSON 对象。例如动作可为 `{"kind":"fill","ref":"实际输入框引用","value":"待填写的普通文本"}` 和 `{"kind":"click","ref":"实际按钮引用"}`。相同控件在连续观察中保留引用。节点被移除或替换后,收到 `stale_ref` 时重新观察并核对目标。可见标签返回 `role:"label"` 时用 `click` 勾选关联控件。密码使用 `fillCredential` 和当前工作区、站点已绑定的 `credentialRef`。
50
- 4. 对 `queued` 或 `running` 回执,使用同一个 `operationId` 和 `workspaceId` 调用 `getOperation`,直至终态。再次 `observe` 核对页面业务结果。若结果为 `outcome_unknown`,先核对页面;导航或用户交回控制权后,重新观察再构造新动作。
51
- 5. 已有会话或凭据可用时自动继续;缺少凭据时只提示缺少的引用,用户在浏览器工具栏的 **open-browser 工作区** 扩展中核对站点并点 **绑定凭据** 后继续。需要用户操作时用 `handOff`。在 macOS 桌面应用中,用户可点击受管页面底部的「人工接管」和「交回 Agent」。工具栏也可切换控制权;缺凭据时可从弹出的面板接管。接管覆盖整个工作区,用户点 **交回 Agent** 后重新观察。整项任务完成后,Agent 在向用户报告前调用 `finishWorkspace`,将结果页放入 `keepPageIds`;没有要交付的页面时传空数组。一次动作完成后仍需继续任务时沿用原工作区。
52
-
53
- macOS 桌面版把任务页面放进 Chromium 原生标签组。新建工作区仍共享应用专用 profile 内同站点的登录态,判断当前账号时请以页面实际显示为准。仅操作任务返回的页面句柄。登录流程打开新窗口时,从工作区页面清单按 openerPageId 和 openedByOperationId 找到对应子页。脚本工作线程受受管页策略约束。
54
-
55
- 省略 `agentName` 时可通过 `OPEN_BROWSER_AGENT_NAME` 配置默认名称。MCP 优先读取握手中的客户端标题,再读取名称。CLI 和 SDK 在已知 Codex 会话环境下显示 Codex,其他情况下分别显示 CLI 和 SDK。显示名称用于识别工作区创建者,访问权限由本机服务验证。
56
-
57
- 在项目根目录创建试用工作区可运行以下命令。
58
-
59
- ```sh
60
- ob="$PWD/skills/open-browser/scripts/open-browser"
61
- printf '%s\n' '{"name":"CLI 试用","agentName":"页面核验助手"}' | "$ob" createWorkspace
62
- ```
63
-
64
- 需要同时使用两个账号时,先给服务和调用端设置相同的 `OPEN_BROWSER_PROFILE`。每个 profile 使用自己的 Chromium 登录资料、本机服务和回执;同一 profile 的工作区仍共享站点账号。已配对的客户端通过 `OPEN_BROWSER_CLIENT_TOKEN_FILE` 选择自己的令牌。管理者可从本机 CLI 签发、委托和撤销权限,详见仓库 README。
65
-
66
- - `act` 支持 `select` 和 `wait`。选择项使用最近观察中 combobox 的 ref 和选项 value。等待条件任选可见文本 `text`、完整页面地址 `url` 或可见元素 `element:{role,name}`,动作等待的 `timeoutMs` 为 1 到 10000。动作请求还可传顶层 `timeoutMs`,它是覆盖排队和执行的 1 到 60000 毫秒 wall budget。提交后等结果页的条件可与点击放在一批。用操作回执和网站结果共同核对业务完成。
67
- - 控件可返回 `checked`、`pressed`、`expanded`、`selected`。其中 `checked` 和 `pressed` 可为 `"mixed"`。用 `{"kind":"setChecked","ref":"…","checked":true}` 要求目标状态,成功后从观察或 `delta.changed` 读回。
68
- - 精确寻找主页面按钮时,传 `observe.locator`,例如 `{"role":"button","name":"Save","within":{"role":"region","name":"Order B"}}`。仅 `match.status:"unique"` 返回可操作引用。重名时查看 `match.candidates` 的容器再缩小范围。存在模态对话框时,`foreground` 给出标题及边界,可操作列表只包含前景内容。
69
- - 在同批点击后用 `{"kind":"wait","navigation":"commit","timeoutMs":3000}`,从回执 `navigation` 区分 `document_committed`、`same_document` 和超时的 `not_committed`。再用 `wait.element` 指定 `checked` 等期望状态,或用 `wait.absent:{role,name}` 等待可操作控件消失。已派发的提交发生超时时,先核对网站结果。
70
- - `observeAfter:"full"` 返回当次操作后的观察,`"delta"` 返回变化的文字和控件。文档或基线更换时可收到全量观察;旧代次、历史回执或页面已变更时,请再次观察。`includeFrames:true` 用于读取已授权的可见一级 frame 文本。需要操作嵌入控件时,传 `frameControls:true`,使用返回的 `frames[].elements[].ref`。框架重新加载后重新观察。
71
- - 交付调用 `finishWorkspace`,传 `workspaceId`、唯一 `operationId` 及 `keepPageIds` 数组。保留的页面脱离任务,未选中的受管页关闭。重试沿用同一操作 ID 和同一页集合;收到 `outcome_unknown` 时先核实页面。用户也可从工作区面板选择保留页。新打开的普通标签无需清理。
72
- - `listOperations` 查询结束的工作区回执;`listEvents` 使用 `after`、`limit` 续读。事件序号从响应的 `nextCursor` 取得。默认保留 7 天。使用随机操作 ID,避免把账号、URL 或正文写入 ID。
73
-
74
- 画布、拖拽或触摸操作先运行 `capabilities`。具有页面像素权限时,调用 `captureVisual`,传页面句柄及可选的 `region:{x,y,width,height}` 或最新元素 `ref`。PNG 的左上角对应返回的 `clip.x,clip.y`,坐标均为视口 CSS 像素。返回的 `frameId` 有效 8 秒,可用一次。通过 `act` 传同一帧的文档和控制代次,以及 `{"kind":"spatial","frameId":"<帧 ID>","action":{"type":"click","x":50,"y":50}}`。可用类型包括 click、hover、tap、drag(toX/toY)、scroll(deltaX/deltaY)、key(keys)和 text(text)。表单控件及私有区域已遮盖,登录继续使用语义引用。遇到 `stale_visual_frame` 时重新截图;若操作回执为 `outcome_unknown`,先核对业务结果。像素权限由本机管理员通过 `admin.setPixelPermission` 授予到指定工作区、调用方及来源。
75
-
76
- ### 长页面、弹窗和下载
77
-
78
- - `observe` 返回 `truncated:true` 和 `nextCursor` 时,把页面句柄与 `cursor:nextCursor` 一起传给下一次 `observe`。知道目标名称时可直接传 `name` 做子串匹配。也可以传 `region:{x,y,width,height}` 按页面视口 CSS 像素选区。每批控件数量可用 `limit` 指定,取值 1 到 180。收到 `stale_cursor` 时重新观察。
79
- - 点击持续被遮罩挡住会以 `target_obscured` 结束。读取最新页面、等待遮罩消失后,用新的操作号点击。收到 `inspect_before_retry` 时,先查站点提交结果再决定下一步。
80
- - 登录流程从一次受管点击打开获准的 HTTP(S) 地址后,读操作回执的 `openedPageIds`。延迟开窗时也可通过 `getWorkspace` 找到发起这次操作的子页,以其句柄继续登录。
81
- - 下载发生后用 `listDownloads` 查询当前工作区,通过 `downloadId` 区分同名文件。`cancelDownload` 需要工作区控制权限。用户在工作区面板保留所需文件后再交付任务,查看文件时以面板显示的路径为准。
82
- - 用户保留文件后,`listOutputs` 返回本地 manifest。Agent 可用 `readOutput` 按 `offset` 和 `limit`(最多 64 KiB)读取 base64 分块,使用 `nextOffset` 续读。输出默认只保留 24 小时,凭据和页面正文不会写入 manifest。
83
-
84
- 原生对话框出现时,读取 `getWorkspace.pendingDialogs`,按页面、操作号、来源及对话框类型核实用途。用 `respondDialog` 传工作区、页面、dialogId、controlGeneration、accept,prompt 可另传 text。每个对话框只回应一次。用户可以在工作区扩展接管并处理。Playwright 无法标识对话框的发起 frame,多来源的 frame 树按取消处理。
85
-
86
- 上传时,用户在工作区扩展选定页面、核对来源并选择文件。调用 `listUploads` 取得该工作区的 fileId,再发送 `act` 动作 `{"kind":"upload","ref":"最近观察中的文件选择按钮","fileId":"用户授权的 ID"}`。单文件至多 8 MiB,只在当前页面、文档、来源和控制代次有效,五分钟失效。发给站点后即消耗授权。结果待核实时应先检查站点。
87
-
88
- 点击前以 `eventCursor` 保存工作区 nextCursor,触发后调用 `waitForEvent`,传同一页面句柄、after、kind(popup / download / dialog)、可选 operationId 和 timeoutMs(1–10000)。也可先发起等待再点击。超时返回 event:null,可从原游标继续;收到事件后使用 nextCursor。resourceId 对应子页、下载或对话框 ID。异步下载只能可靠归到页面时,省略 operationId 过滤。只读委托可查看事件,响应对话框和上传仍需控制权。
89
-
90
- - 中断后用 `getRecoverySummary` 传工作区 ID。对 `observe` 标记的页重新观察,`handle_unavailable` 表示旧句柄已失效。对 `verify_site` 先核对网站结果,`already_completed` 表示已记录完成。交付回执的 `keptPageIds` 记录已移交的标签,`deliveries` 列出已确认保留的下载 ID,`outputs` 列出可续读的本地输出 ID。回执与资料分页分别使用 `nextCursor → after` 和 `nextObjectCursor → objectsAfter`。
91
-
92
- - 创建工作区可传 `profileId`,服务核对它与已连接账号资料一致,返回并在接管面板显示资料名。多个账号分别启动对应的 `OPEN_BROWSER_PROFILE` 实例。CLI、MCP 通过同名环境配置连接,SDK 可用 `new OpenBrowserClient({profileId:'work'})` 选择本机已启动的命名实例。
93
-
94
- ### 按网站运行流程
95
-
96
- 将 [登录后导出](workflows/login-export.json) 或 [上传后核对](workflows/upload-verify.json) 保存为本地模板,按实际站点填写精确的 `origin`、控件角色、名称和成功条件。调用 `runWorkflow` 时传页面句柄、最新 `documentId`、`controlGeneration`、唯一 `operationId`、模板对象 `workflow`,以及本次运行的 `bindings`。例如 `{"attachment":"已授权 fileId"}` 或 `{"password":"已绑定 credentialRef"}`。模板仅保存参数名,每次运行时提供授权引用。服务端逐步重新观察、核对来源和控制权。
97
-
98
- 用 `getOperation` 查看已完成步数。遇到 `target_ambiguous`、`target_missing` 或 `workflow_origin_changed` 时核对页面和已执行步骤。登录后导出还应读取当前工作区的下载回执,核对交付物。
99
-
100
- - 使用 `capabilities` 确认服务提供的方法和限额,`--schema` 输出当前 CLI 的全部方法和参数。遇到不支持的方法时以服务端返回的能力为准。
101
- - `diagnoseOperation` 接受 `workspaceId` 和 `operationId`,返回已完成步数、是否记录过派发、故障类别和建议处置。桌面工作区面板也可预览并保存同一份脱敏 JSON。结果为 `check_site_result` 时先用页面的业务结果核实是否生效。
102
-
103
- 单页快捷入口
104
-
105
- 只需打开一个明确网址时,可直接调用 `open`,它会创建工作区并返回页面句柄。需要继续在同一任务中打开页面时,再按上面的 `createWorkspace` 和 `openPage` 流程操作。
106
-
107
- 当 `observe` 返回 `blockedRequests` 或 `getWorkspace` 返回 `blockedOrigins` 时,先核对来源和资源类型。用户或 Agent 取得当前工作区控制权后,可用 `grantOrigin` 传入最新 `controlGeneration`、完整 `origin` 和 `scope`。`resource` 只放行图片、字体、样式和媒体,`navigation` 才允许文档和脚本等完整站点能力。授权后重新 `observe` 或重新执行原操作。
20
+ For a missing workspace, expired grant or CLI wrapper, read the [recovery guide](references/recovery.en.md). For canvases, frames, files and account profiles, read [operations and permissions](references/operations.en.md). Use `--schema` to inspect parameters supported by the installed version.
@@ -0,0 +1,22 @@
1
+ ---
2
+ name: open-browser
3
+ description: 用户要求用 open-browser 浏览、观察页面、操作工作区或验证登录时,通过 open-browser CLI 控制其独立 Chromium。
4
+ ---
5
+
6
+ [English](SKILL.md)
7
+
8
+ ## 从当前任务开始
9
+
10
+ 1. **继续已有页面。** 用 `getWorkspace`(或 `listWorkspaces` 找回任务)取得页面句柄,用 `reattachPage` 读当前观察。普通已登录标签需要一个命名的空工作区。创建后先保存 `eventCursor.nextCursor`,请用户在目标标签的扩展中选择任务并点击「让 Agent 操作此页」。用 `waitForEvent` 传 `workspaceId`、`kind:"page_bound"`、`after`,再用事件的 `pageId` 调用 `reattachPage`。等待超时可沿用原游标。
11
+ 2. **新开页面。** 用 `open` 传明确的任务 `name` 和 `url`,保存返回的工作区与页面 ID,再 `observe`。在已有任务中增加页面用 `openPage`。并行 Agent 可以传各自的 `agentName`。
12
+ 3. **人工交回。** 用户处理登录或弹窗时用 `handOff`。用原句柄调用 `reattachPage` 并传 `waitMs:30000`,用户点击「交回 Agent」后直接使用返回的观察。工作区的 `mode` 表示控制权,页面的 `readyForAgent` 表示当前是否可操作。
13
+
14
+ ## 执行动作
15
+
16
+ macOS 和 Linux 使用本 Skill 的 `scripts/open-browser`,Windows 使用 `scripts/open-browser.cmd`。首次调用会探测本机服务并按需启动应用。连续任务优先复用 SDK 客户端或运行启动器的 `session` 命令,每行发送 `{"id":1,"method":"…","params":{…}}`。
17
+
18
+ 用最新观察的控件 ref 调用 `observeAndAct`,传唯一 `operationId`、`actions`、`observeAfter:"delta"` 和 `waitMs:3000`。完成时直接读取回执的变化。回执仍为 queued 或 running 时,用同一个操作号调用 `getOperation` 并传 `waitMs`(最多 10000 毫秒)。`outcome_unknown` 先核对站点结果。密码使用工作区绑定的 `credentialRef`。任务完成前调用 `finishWorkspace`,通过 `keepPageIds` 指定交付页面。
19
+
20
+ 找不到工作区、授权失效或需要封装 CLI 时,参阅[页面恢复与错误处理](references/recovery.md)。画布、跨框架、上传下载及多账号操作见[操作与授权](references/operations.md)。用 `--schema` 查看本机版本支持的参数。
21
+
22
+ <!-- source-sha256: e145ff28b3dd87c5cba7e6c13692f494886834d3b255785851ff3308267d9254 -->
@@ -0,0 +1,3 @@
1
+ ### macOS
2
+
3
+ The launcher connects to the desktop app’s local service. Run `npm start` in the source checkout or open `/Applications/open-browser.app` for a visible window. The floating bar at the bottom of a managed page includes **Take over**.
@@ -0,0 +1,5 @@
1
+ ### macOS
2
+
3
+ 在 macOS 桌面版中,Skill 会优先连接应用内本机服务。需要打开浏览器窗口时运行 `npm start` 或打开 `/Applications/open-browser.app`。受管页面的人工接管按钮位于页面底部悬浮栏。
4
+
5
+ <!-- source-sha256: 0d91ded30ccd446f373a7d1f481416b21d2a495fb76d00e3ec99b95b2f1f2e84 -->