@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
@@ -1,54 +1,54 @@
1
1
  <!doctype html>
2
- <html lang="zh-CN">
2
+ <html lang="en">
3
3
  <head>
4
4
  <meta charset="utf-8">
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1">
6
- <title>open-browser 工作区</title>
6
+ <title data-i18n>Open Browser Workspace</title>
7
7
  <link rel="icon" type="image/png" href="icons/open-browser-32.png">
8
8
  <link rel="stylesheet" href="popup.css">
9
- <script defer src="workspace-title.js"></script>
10
- <script defer src="phase-labels.js"></script>
11
- <script defer src="popup.js"></script>
9
+ <script type="module" src="page-locale.js"></script>
12
10
  </head>
13
11
  <body>
14
- <header><strong><img src="icons/open-browser-48.png" width="24" height="24" alt="">open-browser</strong><span id="status" role="status">正在连接…</span></header>
12
+ <header><strong><img src="icons/open-browser-48.png" width="24" height="24" alt="">open-browser</strong><span data-i18n id="status" role="status">Connecting…</span></header>
15
13
  <main>
16
- <p id="empty" hidden>当前没有活动任务。新标签页会显示 Agent 控制台。</p>
14
+ <p data-i18n id="empty" hidden>No active tasks. Open a new tab to see the Agent Console.</p>
17
15
  <section id="adoption" hidden>
18
16
  <p id="adopt-site"></p>
19
- <label for="adopt-task">授权给哪个 Agent 任务</label><select id="adopt-task"></select>
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>
22
- <label id="adopt-result" hidden>将以下授权交给所选 Agent,两分钟内有效<input id="adopt-token" readonly></label>
17
+ <label data-i18n for="adopt-task">Agent task to authorize</label><select id="adopt-task"></select>
18
+ <label data-i18n for="adopt-alias">Account alias (optional)</label><input data-i18n-attrs="placeholder" id="adopt-alias" maxlength="48" placeholder="For example, Work account">
19
+ <label data-i18n><input type="checkbox" id="resume-tab">Restore the last browser session on restart and resume this task</label>
20
+ <div class="action"><button data-i18n id="adopt" type="button">Give this tab to the agent</button><button data-i18n class="secondary" id="adopt-manual" type="button">Generate backup authorization code</button></div>
21
+ <label data-i18n id="adopt-result" hidden>Send this authorization to the selected agent within two minutes<input id="adopt-token" readonly></label>
23
22
  </section>
24
23
  <section id="workspace" hidden>
25
24
  <div id="context-selection" hidden>
26
- <label for="workspaces">工作区</label><select id="workspaces"></select>
27
- <label for="pages">标签页</label><select id="pages"></select>
25
+ <label data-i18n for="workspaces">Workspace</label><select id="workspaces"></select>
26
+ <label data-i18n for="pages">Tabs</label><select id="pages"></select>
28
27
  </div>
29
28
  <p id="page-details"></p>
30
29
  <div class="action"><button id="control" type="button"></button></div>
31
30
  <div id="dialogs"></div>
32
31
  <div id="blocked"></div>
33
- <details id="uploads"><summary>授权上传文件</summary><p id="upload-origin"></p>
32
+ <details id="uploads"><summary data-i18n>Allow file uploads</summary><p id="upload-origin"></p>
34
33
  <input id="upload-file" type="file"><div id="upload-list"></div></details>
35
- <details id="downloads" hidden><summary>任务下载</summary><div id="download-list"></div></details>
34
+ <details id="downloads" hidden><summary data-i18n>Task downloads</summary><div id="download-list"></div></details>
35
+ <button id="pixel-permission" type="button" class="secondary" hidden></button>
36
36
  <p id="visual-status" hidden></p>
37
- <details><summary>导出错误日志</summary>
38
- <p>导出当前任务的脱敏失败记录,便于排查问题。</p>
39
- <button id="diagnostic-export-button" type="button" class="secondary">导出错误日志</button>
40
- <a id="diagnostic-export" download="open-browser-error-log.json" hidden>下载错误日志</a>
37
+ <details><summary data-i18n>Export error log</summary>
38
+ <p data-i18n>Export redacted failures for this task to help diagnose problems.</p>
39
+ <button data-i18n id="diagnostic-export-button" type="button" class="secondary">Export error log</button>
40
+ <a data-i18n id="diagnostic-export" download="open-browser-error-log.json" hidden>Download error log</a>
41
41
  </details>
42
- <details id="delivery"><summary>结束任务</summary>
43
- <p>勾选要留给自己的标签,其余任务标签将关闭。</p>
44
- <div id="keep"></div><button id="finish" type="button">结束</button>
42
+ <details id="delivery"><summary data-i18n>Finish task</summary>
43
+ <p data-i18n>Select the tabs to keep. The other task tabs will close.</p>
44
+ <div id="keep"></div><button data-i18n id="finish" type="button">Finish</button>
45
45
  </details>
46
46
  </section>
47
47
  <form id="credential" hidden>
48
- <h2>补充凭据</h2>
48
+ <h2 data-i18n>Supply credentials</h2>
49
49
  <p id="credential-target"></p>
50
- <label for="secret">凭据值</label><input id="secret" type="password" autocomplete="off" required>
51
- <div class="action"><button id="save" type="submit">绑定凭据</button></div>
50
+ <label data-i18n for="secret">Credential value</label><input id="secret" type="password" autocomplete="off" required>
51
+ <div class="action"><button data-i18n id="save" type="submit">Bind credential</button></div>
52
52
  </form>
53
53
  <p id="notice" role="status" hidden></p>
54
54
  </main>
@@ -1,8 +1,10 @@
1
- 'use strict';
1
+ import { errorLabel, phases } from './phase-labels.js';
2
+
3
+ const { t } = globalThis.openBrowserI18n;
2
4
 
3
5
  const el = id => document.getElementById(id);
4
6
  let selected = '', detail, request, selectedTab = '', revision = 0, busy = false, refreshing = false, contextTab = false;
5
- const phases = globalThis.openBrowserPhaseLabels;
7
+ const workspaceTitle = globalThis.openBrowserWorkspaceTitle;
6
8
 
7
9
  async function call(method, params = {}) {
8
10
  const reply = await chrome.runtime.sendMessage({ method, params });
@@ -16,14 +18,15 @@ function notify(text = '') {
16
18
  }
17
19
 
18
20
  function describe(w) {
19
- if (w.activity?.needsHumanVerification) return '需要人工验证';
20
- if (w.mode === 'human') return '人工接管';
21
- if (w.mode === 'transferring') return '交接中';
22
- if (w.activity?.needsCredential) return '等待凭据';
21
+ if (w.activity?.needsHumanVerification) return t("Human verification required");
22
+ if (w.mode === 'human') return t("Human in control");
23
+ if (w.mode === 'transferring') return t("Transferring");
24
+ if (w.activity?.needsCredential) return t("Waiting for credentials");
25
+ if (w.activity?.needsVisualPermission) return t("Screenshot permission required");
23
26
  const current = w.activity?.current;
24
27
  const stage = current?.dispatchState;
25
- if (stage) return stage === 'dispatched' ? '已派发' : '等待页面';
26
- return phases[current?.phase] || phases[w.activity?.phase] || 'Agent 控制';
28
+ if (stage) return stage === 'dispatched' ? t("Dispatched") : t("Waiting for page");
29
+ return phases[current?.phase] || phases[w.activity?.phase] || t("Agent in control");
27
30
  }
28
31
 
29
32
  function options(node, entries, value) {
@@ -42,36 +45,44 @@ function showCredential(next) {
42
45
  el('credential').hidden = !next;
43
46
  if (!next) return;
44
47
  el('credential-target').textContent = next.origin + ' · ' + next.credentialRef;
45
- el('save').textContent = '绑定凭据';
48
+ el('save').textContent = t("Bind credential");
46
49
  }
47
50
 
48
- let popupTabId, ordinaryTarget, tokenTimer, standalone = false;
51
+ let popupTabId, ordinaryTarget, tokenTimer, standalone = false, initialized = false;
49
52
  function clearToken() {
50
53
  clearTimeout(tokenTimer);
51
54
  el('adopt-token').value = '';
52
55
  el('adopt-result').hidden = true;
53
56
  }
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
- });
57
+ el('adopt-task').onchange = () => { clearToken(); el('adopt-manual').disabled = el('adopt').disabled = !el('adopt-task').value; };
58
+ function authorizeTab(bindOnApproval) {
59
+ return perform(async () => {
60
+ clearToken();
61
+ const {id:targetId, origin} = ordinaryTarget;
62
+ const reply = await call('offerCurrentTab',{workspaceId:el('adopt-task').value, tabId:popupTabId,
63
+ targetId, origin, bindOnApproval, resumeOnRestart:el('resume-tab').checked, accountAlias:el('adopt-alias').value.trim()});
64
+ if (bindOnApproval && reply.pageId) {
65
+ notify(t("This tab is now assigned to the selected task."));
66
+ return;
67
+ }
68
+ el('adopt-token').value = JSON.stringify({workspaceId:reply.workspaceId,adoptionToken:reply.adoptionToken});
69
+ el('adopt-result').hidden = false;
70
+ el('adopt-token').select();
71
+ tokenTimer = setTimeout(clearToken, Math.max(0, reply.expiresAt - Date.now()));
72
+ });
73
+ }
74
+ el('adopt').onclick = () => authorizeTab(true);
75
+ el('adopt-manual').onclick = () => authorizeTab(false);
65
76
 
66
77
  let deliveryKey = '', finishId;
67
78
  function renderDelivery(w) {
68
- const originLabels = {resource:'加载静态资源',navigation:'允许导航与页面操作'};
79
+ const originLabels = {resource:t("Load static resources"),navigation:t("Allow navigation and page actions")};
69
80
  const blocks = (w.blockedOrigins || []).filter(item => originLabels[item.scope]);
70
81
  el('blocked').replaceChildren(...blocks.map(item => {
71
82
  const button = document.createElement('button');
72
83
  button.type = 'button';
73
84
  button.className = 'secondary';
74
- button.textContent = '本次' + originLabels[item.scope] + ' · ' + item.origin;
85
+ button.textContent = t("For this task: {0} · {1}", originLabels[item.scope], item.origin);
75
86
  button.onclick = () => perform(() => call('grantOrigin',{workspaceId:w.workspaceId,
76
87
  controlGeneration:w.controlGeneration,origin:item.origin,scope:item.scope}));
77
88
  return button;
@@ -88,7 +99,7 @@ function renderDelivery(w) {
88
99
  input.disabled = p.ownership === 'user';
89
100
  input.value = p.pageId;
90
101
  input.onchange = () => { finishId = crypto.randomUUID(); };
91
- label.append(input, ' ' + (p.title || p.origin || '页面'));
102
+ label.append(input, ' ' + (p.title || p.origin || t("Page")));
92
103
  return label;
93
104
  }));
94
105
  }
@@ -96,8 +107,8 @@ el('finish').onclick = () => perform(async () => {
96
107
  const keepPageIds = [...el('keep').querySelectorAll('input:checked')].map(input => input.value);
97
108
  const receipt = await call('finishWorkspace',{workspaceId:selected,keepPageIds,operationId:finishId,
98
109
  controlGeneration:detail.controlGeneration});
99
- if (receipt.state !== 'completed') { notify('交付待核实 · ' + receipt.operationId); return; }
100
- notify('已保留 ' + receipt.keptPageIds.length + ' 页,已关闭 ' + receipt.closedPageIds.length + ' 页。');
110
+ if (receipt.state !== 'completed') { notify(t("Delivery needs verification · {0}", receipt.operationId)); return; }
111
+ notify(t("Pages kept: {0} · Pages closed: {1}", receipt.keptPageIds.length, receipt.closedPageIds.length));
101
112
  render(null);
102
113
  });
103
114
 
@@ -120,7 +131,7 @@ el('diagnostic-export-button').onclick = () => perform(async () => {
120
131
  const link = el('diagnostic-export');
121
132
  link.href = URL.createObjectURL(new Blob([text], {type:'application/json'}));
122
133
  link.hidden = false;
123
- link.textContent = '下载错误日志';
134
+ link.textContent = t("Download error log");
124
135
  link.click();
125
136
  });
126
137
 
@@ -133,26 +144,26 @@ function render(w) {
133
144
  el('workspace').hidden = !w;
134
145
  el('empty').hidden = !!w;
135
146
  el('context-selection').hidden = contextTab || !w;
136
- el('status').textContent = w ? describe(w) + ' · 资料 ' + w.profileId : '暂无工作区';
147
+ el('status').textContent = w ? t("{0} · Profile {1}", describe(w), w.profileId) : t("No workspaces");
137
148
  if (!w) { showCredential(null); return; }
138
149
  renderDialogs(w);
139
150
  renderDelivery(w);
140
151
  const pages = w.pages || [];
141
152
  if (standalone && !selectedTab) selectedTab = pages[0]?.pageId || '';
142
153
  const page = pages.find(p => p.pageId === selectedTab);
143
- options(el('pages'), pages.map((p, i) => [p.pageId, (i+1) + ' · ' + (p.title || p.origin || '页面')]), selectedTab);
154
+ options(el('pages'), pages.map((p, i) => [p.pageId, (i+1) + ' · ' + (p.title || p.origin || t("Page"))]), selectedTab);
144
155
  if (!page) {
145
156
  el('workspace').hidden = !standalone;
146
157
  el('control').disabled = true;
147
158
  el('uploads').hidden = true;
148
159
  el('page-details').textContent = '';
149
- el('status').textContent = '原标签页已关闭或解绑';
160
+ el('status').textContent = t("The original tab was closed or detached.");
150
161
  showCredential(null);
151
162
  return;
152
163
  }
153
- const sync = page.lastSyncedAt ? '上次同步 ' + new Date(page.lastSyncedAt).toLocaleTimeString() : '';
154
- el('page-details').textContent = [page.origin, w.accountAlias, page.syncState === 'sync_pending' ? '同步中' : sync].filter(Boolean).join(' · ');
155
- el('control').textContent = w.unlockPending ? '重试人工接管' : w.mode === 'human' ? '交回 Agent' : w.scope === 'single_tab' ? '接管此页' : '接管工作区';
164
+ const sync = page.lastSyncedAt ? t("Last synced {0}", new Date(page.lastSyncedAt).toLocaleTimeString(globalThis.openBrowserI18n.locale)) : '';
165
+ el('page-details').textContent = [page.origin, w.accountAlias, page.syncState === 'sync_pending' ? t("Syncing") : sync].filter(Boolean).join(' · ');
166
+ el('control').textContent = w.unlockPending ? t("Retry takeover") : w.mode === 'human' ? t("Return to agent") : w.scope === 'single_tab' ? t("Take over this tab") : t("Take over workspace");
156
167
  el('control').disabled = busy || (w.mode === 'transferring' && !w.unlockPending) || (!selectedTab && w.mode !== 'human');
157
168
  el('uploads').hidden = w.mode!=='agent' || !selectedTab;
158
169
  el('upload-origin').textContent = pages.find(p=>p.pageId===selectedTab)?.origin || '';
@@ -187,12 +198,12 @@ async function sync() {
187
198
  const tasks = list.filter(w => w.pageAvailability === 'unregistered' && w.mode === 'agent');
188
199
  el('adoption').hidden = false;
189
200
  el('empty').hidden = true;
190
- el('status').textContent = '普通标签页';
191
- el('adopt-site').textContent = origin.origin + (tasks.length ? '' : ' · 请让 Agent 先创建一个命名工作区');
201
+ el('status').textContent = t("Ordinary tab");
202
+ el('adopt-site').textContent = origin.origin + (tasks.length ? '' : t(" · Ask the agent to create a named workspace first"));
192
203
  const chooser = el('adopt-task');
193
204
  options(chooser, tasks.map(w => [w.workspaceId, workspaceTitle(w) + ' · ' + w.workspaceId.slice(0,8)]),
194
205
  tasks.some(w => w.workspaceId === chooser.value) ? chooser.value : tasks.length === 1 ? tasks[0].workspaceId : '');
195
- el('adopt').disabled = !chooser.value;
206
+ el('adopt-manual').disabled = el('adopt').disabled = !chooser.value;
196
207
  return;
197
208
  }
198
209
  const list = contextTab ? (selected ? [await call('getWorkspace', {workspaceId: selected })] : []) : await call('listWorkspaces');
@@ -212,7 +223,7 @@ async function sync() {
212
223
  options(el('workspaces'), entries, selected);
213
224
  const w = contextTab ? list[0] || null : selected ? await call('getWorkspace', { workspaceId: selected }) : null;
214
225
  const [captureReply, downloads, uploads] = w ? await Promise.all([
215
- call('visualStatus',{workspaceId:selected}).catch(()=>({})),
226
+ call('visualStatus',{workspaceId:selected,pageId:selectedTab}).catch(()=>({})),
216
227
  call('listDownloads',{workspaceId:selected}),
217
228
  call('listUploads',{workspaceId:selected}),
218
229
  ]) : [{}, [], []];
@@ -221,25 +232,38 @@ async function sync() {
221
232
  render(w);
222
233
  el('upload-list').replaceChildren(...uploads.map(file=>{
223
234
  const button=document.createElement('button');
224
- button.textContent='撤销 '+file.name+' · '+file.origin;
235
+ button.textContent=t("Revoke {0} · {1}", file.name, file.origin);
225
236
  button.onclick=()=>perform(()=>call('revokeUpload',{workspaceId:w.workspaceId,fileId:file.fileId}));
226
237
  return button;
227
238
  }));
228
239
  renderDownloads(downloads);
240
+ const permission = captureReply.pagePermission;
241
+ const button = el('pixel-permission');
242
+ const pageId = selectedTab;
243
+ button.hidden = !permission;
244
+ if (permission) {
245
+ button.textContent = permission.allow ? t("Revoke screenshot permission for this task · {0}", permission.origin) : t("Allow screenshots for this task · {0}", permission.origin);
246
+ button.onclick = () => perform(() => call('setPagePixelPermission',{
247
+ workspaceId:w.workspaceId, pageId, documentId:permission.documentId, controlGeneration:w.controlGeneration,
248
+ origin:permission.origin, allow:!permission.allow
249
+ }));
250
+ }
229
251
  const status=el('visual-status');
230
252
  status.hidden=!capture;
231
- if(capture) status.textContent='最近画面采集 · '+capture.principalId+' · '+capture.origin+' · ('+
232
- capture.clip.x+', '+capture.clip.y+') '+capture.clip.width+' × '+capture.clip.height;
253
+ if (capture) {
254
+ const { x, y, width, height } = capture.clip;
255
+ status.textContent = t("Last capture · {0} · {1} · {2}", capture.principalId, capture.origin, `(${x}, ${y}) ${width} × ${height}`);
256
+ }
233
257
  }
234
258
  } catch (error) {
235
259
  if (serial === revision) {
236
260
  render(null);
237
261
  if (contextTab && error.message === 'workspace_not_found') {
238
- el('status').textContent = '原任务已结束或服务已重启';
239
- notify('请在需要授权的标签页重新打开扩展。');
262
+ el('status').textContent = t("The task ended or the service restarted.");
263
+ notify(t("Reopen the extension on the tab you want to authorize."));
240
264
  } else {
241
- el('status').textContent = '连接失败';
242
- notify(error.message);
265
+ el('status').textContent = t("Connection failed");
266
+ notify(errorLabel(error.message));
243
267
  }
244
268
  }
245
269
  } finally {
@@ -255,23 +279,34 @@ function renderDialogs(w) {
255
279
  panel.dataset.signature = signature;
256
280
  panel.replaceChildren(...items.map(item => {
257
281
  const row = document.createElement('div');
258
- row.textContent = item.origin + ' · ' + item.type + ' · ' + item.message;
282
+ const caption = document.createElement('span');
283
+ const labels = [];
284
+ const bindLabel = renderLabel => { labels.push(renderLabel); renderLabel(); };
285
+ row.updateLanguage = () => labels.forEach(renderLabel => renderLabel());
286
+ bindLabel(() => {
287
+ caption.textContent = [item.origin, {alert:t('Alert'), confirm:t('Confirmation'), prompt:t('Prompt')}[item.type] || item.type, item.message].join(' · ');
288
+ });
289
+ row.append(caption);
259
290
  if (w.mode === 'agent') {
260
291
  const take = document.createElement('button');
261
- take.textContent = '接管并处理';
292
+ bindLabel(() => { take.textContent = t("Take over to respond"); });
262
293
  take.onclick = () => {
263
294
  take.disabled = true;
264
295
  void call('takeControl',{workspaceId:w.workspaceId,pageId:item.pageId,controlGeneration:w.controlGeneration})
265
- .catch(error=>notify(error.message)).finally(()=>void sync());
296
+ .catch(error=>notify(errorLabel(error.message))).finally(()=>void sync());
266
297
  };
267
298
  row.append(take);
268
299
  return row;
269
300
  }
270
301
  const input = document.createElement('input');
271
- if (item.type === 'prompt') { input.placeholder = '回复'; input.maxLength = 2048; row.append(input); }
302
+ if (item.type === 'prompt') {
303
+ bindLabel(() => { input.placeholder = t("Reply"); });
304
+ input.maxLength = 2048;
305
+ row.append(input);
306
+ }
272
307
  for (const accept of [true,false]) {
273
308
  const button = document.createElement('button');
274
- button.textContent = accept ? '确定' : '取消';
309
+ bindLabel(() => { button.textContent = accept ? t("OK") : t("Cancel"); });
275
310
  button.onclick = () => perform(() => call('respondDialog',{workspaceId:w.workspaceId,pageId:item.pageId,
276
311
  dialogId:item.dialogId,controlGeneration:w.controlGeneration,accept,
277
312
  ...(accept && item.type === 'prompt' && {text:input.value})}));
@@ -281,9 +316,16 @@ function renderDialogs(w) {
281
316
  }));
282
317
  }
283
318
 
319
+ export function updateLanguage() {
320
+ if (!initialized) return;
321
+ for (const row of el('dialogs').children) row.updateLanguage();
322
+ if (detail && !busy) render(detail);
323
+ void sync();
324
+ }
325
+
284
326
  function renderDownloads(items) {
285
327
  el('downloads').hidden = !items.length;
286
- const labels = {receiving:'下载中',ready:'待保留',failed:'失败',cancelled:'已取消',kept:'已保留'};
328
+ const labels = {receiving:t("Downloading"),ready:t("Ready to keep"),failed:t("Failed"),cancelled:t("Cancelled"),kept:t("Kept")};
287
329
  el('download-list').replaceChildren(...items.map(item => {
288
330
  const row = document.createElement('p');
289
331
  row.textContent = item.filename + ' · ' + labels[item.state] + ' ';
@@ -296,8 +338,8 @@ function renderDownloads(items) {
296
338
  }
297
339
  const params = {workspaceId:item.workspaceId,downloadId:item.downloadId};
298
340
  if (item.state === 'ready' || item.state === 'kept')
299
- button(item.state === 'kept' ? '查看保存位置' : '保留文件', async () => notify((await call('keepDownload',params)).path));
300
- if (item.state === 'receiving' || item.state === 'ready') button('取消', () => call('cancelDownload',params));
341
+ button(item.state === 'kept' ? t("Show saved location") : t("Keep file"), async () => notify((await call('keepDownload',params)).path));
342
+ if (item.state === 'receiving' || item.state === 'ready') button(t("Cancel"), () => call('cancelDownload',params));
301
343
  return row;
302
344
  }));
303
345
  }
@@ -309,7 +351,7 @@ async function perform(action) {
309
351
  notify();
310
352
  const enabled = [...document.querySelectorAll('button:enabled, select:enabled, input:enabled')];
311
353
  for (const element of enabled) element.disabled = true;
312
- try { await action(); } catch (error) { notify(error.message); }
354
+ try { await action(); } catch (error) { notify(errorLabel(error.message)); }
313
355
  finally {
314
356
  busy = false;
315
357
  for (const element of enabled) element.disabled = false;
@@ -344,20 +386,20 @@ el('upload-file').onchange = event => {
344
386
  const target=uploadTarget, current=selectedUploadTarget();
345
387
  uploadTarget=null;
346
388
  if (!target || !current || Object.keys(target).some(key=>target[key]!==current[key])) {
347
- notify('页面或控制权已变更,请重新选择文件。');
389
+ notify(t("The page or control changed. Select the file again."));
348
390
  return;
349
391
  }
350
392
  const params={...target,name:file.name,mimeType:file.type};
351
393
  void perform(async()=>{
352
- if (file.size>8*1024*1024) throw Error('单文件上限 8 MiB');
394
+ if (file.size>8*1024*1024) throw Error(t("Each file must be 8 MiB or smaller."));
353
395
  const data=await new Promise((resolve,reject)=>{
354
396
  const reader=new FileReader();
355
397
  reader.onload=()=>resolve(reader.result.split(',')[1]);
356
- reader.onerror=()=>reject(Error('文件读取失败'));
398
+ reader.onerror=()=>reject(Error(t("Could not read the file.")));
357
399
  reader.readAsDataURL(file);
358
400
  });
359
401
  await call('grantUpload',{...params,data});
360
- notify('已向 '+params.origin+' 授权 '+file.name+',有效期五分钟。');
402
+ notify(t("Granted {0} access to {1} for five minutes.", params.origin, file.name));
361
403
  });
362
404
  };
363
405
  el('control').onclick = () => perform(async () => {
@@ -375,9 +417,9 @@ el('credential').onsubmit = event => {
375
417
  const w = await call('getWorkspace', { workspaceId });
376
418
  const fresh = w.activity?.credentialRequest;
377
419
  if (w.mode !== 'agent' || generation !== w.controlGeneration || !fresh ||
378
- ['pageId', 'origin', 'credentialRef', 'operationId'].some(k => fresh[k] !== pending[k])) throw new Error('凭据请求已变化');
420
+ ['pageId', 'origin', 'credentialRef', 'operationId'].some(k => fresh[k] !== pending[k])) throw new Error(t("The credential request has changed."));
379
421
  await call('resolveCredential', { workspaceId, ...pending, value });
380
- notify('已绑定凭据,调用方可以重试。');
422
+ notify(t("Credential bound. The agent can retry."));
381
423
  });
382
424
  };
383
425
 
@@ -391,6 +433,7 @@ async function open() {
391
433
  contextTab = Boolean(owned);
392
434
  if (owned) { selected = owned.workspaceId; selectedTab = owned.pageId; }
393
435
  }
436
+ initialized = true;
394
437
  await sync();
395
438
  if (explicit?.[2] && detail) el('delivery').open = true;
396
439
  }
@@ -21,24 +21,26 @@ function showRunning(tabId, running) {
21
21
  }
22
22
 
23
23
  const actionStates = {
24
- running: ['▶', '#1556b0', '执行中'],
25
- queued: ['…', '#6757a4', '排队中'],
26
- actionability: ['⌁', '#1556b0', '检查目标'],
27
- dispatching: ['▶', '#1556b0', '正在派发'],
28
- waiting: ['…', '#6757a4', '等待页面'],
29
- verifying: ['✓', '#526675', '核对结果'],
30
- needs_credential: ['!', '#a72f24', '等待凭据'],
31
- needs_human_verification: ['!', '#a75d08', '需要人工验证'],
32
- completed: ['✓', '#526675', '已完成'],
33
- failed: ['!', '#a72f24', '执行失败'],
34
- outcome_unknown: ['?', '#a75d08', '结果待核实'],
35
- cancelled: ['−', '#626977', '已取消'],
36
- idle: ['·', '#626977', '等待指令'],
37
- human: ['人', '#176344', '人工控制'],
38
- transferring: ['↔', '#926407', '交接中'],
24
+ running: ['▶', '#1556b0', "Running"],
25
+ queued: ['…', '#6757a4', "In queue"],
26
+ actionability: ['⌁', '#1556b0', "Checking target"],
27
+ dispatching: ['▶', '#1556b0', "Dispatching"],
28
+ waiting: ['…', '#6757a4', "Waiting for page"],
29
+ verifying: ['✓', '#526675', "Checking result"],
30
+ needs_credential: ['!', '#a72f24', "Waiting for credentials"],
31
+ needs_human_verification: ['!', '#a75d08', "Human verification required"],
32
+ needs_visual_permission: ['!', '#a75d08', "Screenshot permission required"],
33
+ completed: ['✓', '#526675', "Completed"],
34
+ failed: ['!', '#a72f24', "Action failed"],
35
+ outcome_unknown: ['?', '#a75d08', "Outcome unknown"],
36
+ cancelled: ['−', '#626977', "Cancelled"],
37
+ idle: ['·', '#626977', "Waiting for instructions"],
38
+ human: ["H", '#176344', "Human in control"],
39
+ transferring: ['↔', '#926407', "Transferring"],
39
40
  };
40
41
 
41
42
  async function writeAction(tabId, record) {
43
+ await localeReady;
42
44
  const key = tabKey(tabId);
43
45
  if (!record) {
44
46
  showRunning(tabId, false);
@@ -46,23 +48,23 @@ async function writeAction(tabId, record) {
46
48
  if (!await chrome.tabs.get(tabId).catch(() => null)) return;
47
49
  await Promise.all([
48
50
  chrome.action.setPopup({ tabId, popup: defaultPopup }),
49
- chrome.action.setTitle({ tabId, title: 'open-browser 工作区' }),
51
+ chrome.action.setTitle({ tabId, title: t("Open Browser Workspace") }),
50
52
  chrome.action.setBadgeText({ tabId, text: '' }),
51
53
  ]);
52
54
  return;
53
55
  }
54
56
  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;
57
+ const phase = record.mode !== 'agent' ? record.mode : record.needsHumanVerification ? 'needs_human_verification' : record.needsVisualPermission ? 'needs_visual_permission' : record.needsCredential ? 'needs_credential' : record.phase;
56
58
  showRunning(tabId, ['running', 'actionability', 'dispatching', 'waiting', 'verifying'].includes(phase));
57
59
  const [text, color, status] = actionStates[phase] || actionStates.idle;
58
- const panel = phase === 'needs_credential' || phase === 'needs_human_verification' || phase === 'transferring' || !record.controlGeneration;
59
- const steps = { click: '点击', fill: '填写', fillCredential: '填写凭据' };
60
- const step = phase === 'running' && record.dispatchState ? (record.dispatchState === 'dispatched' ? '已派发' : '等待页面') : phase === 'running' ? steps[record.stepKind] : '';
61
- const hint = record.mode === 'human' ? '点击交回 Agent' : panel ? '点击打开工作区面板' : '点击接管';
60
+ const panel = phase === 'needs_credential' || phase === 'needs_human_verification' || phase === 'needs_visual_permission' || phase === 'transferring' || !record.controlGeneration;
61
+ const steps = { click: t("Click"), fill: t("Fill"), fillCredential: t("Fill credential") };
62
+ const step = phase === 'running' && record.dispatchState ? (record.dispatchState === 'dispatched' ? t("Dispatched") : t("Waiting for page")) : phase === 'running' ? steps[record.stepKind] : '';
63
+ const hint = record.mode === 'human' ? t("Click to return control to the agent") : panel ? t("Click to open the workspace panel") : t("Click to take over");
62
64
  await Promise.all([
63
- chrome.action.setBadgeText({ tabId, text }),
65
+ chrome.action.setBadgeText({ tabId, text: t(text) }),
64
66
  chrome.action.setBadgeBackgroundColor({ tabId, color }),
65
- chrome.action.setTitle({ tabId, title: (record.agentName || 'Agent') + ' · ' + (step || status) + ' · ' + hint }),
67
+ chrome.action.setTitle({ tabId, title: (record.agentName || 'Agent') + ' · ' + (step || t(status)) + ' · ' + hint }),
66
68
  chrome.action.setPopup({ tabId, popup: panel ? defaultPopup : '' }),
67
69
  ]);
68
70
  }
@@ -104,7 +106,11 @@ chrome.tabs.onRemoved.addListener(tabId => {
104
106
 
105
107
  async function openWorkspacePanel(tabId, delivery = false) {
106
108
  const url = chrome.runtime.getURL(defaultPopup) + (Number.isInteger(tabId) ? '#tab-' + tabId + (delivery ? '-delivery' : '') : '');
107
- await chrome.windows.create({ url, type: 'popup', width: 380, height: 510, focused: true });
109
+ const size = {width:380, height:510};
110
+ const panel = await chrome.windows.create({ url, type: 'popup', ...size, focused: true });
111
+ // Chromium can apply its startup window size to a newly created popup.
112
+ if (panel.width !== size.width || panel.height !== size.height)
113
+ await chrome.windows.update(panel.id, size);
108
114
  }
109
115
 
110
116
  const toggling = new Set();
@@ -131,7 +137,7 @@ async function clickTabAction(tab) {
131
137
 
132
138
  chrome.action.onClicked.addListener(clickTabAction);
133
139
  chrome.runtime.onInstalled.addListener(() => {
134
- chrome.contextMenus.create({ id: 'workspace-panel', title: '工作区面板', contexts: ['action'] });
140
+ chrome.contextMenus.create({ id: 'workspace-panel', title: t("Workspace panel"), contexts: ['action'] });
135
141
  });
136
142
  chrome.contextMenus.onClicked.addListener((info, tab) => {
137
143
  if (info.menuItemId === 'workspace-panel') void openWorkspacePanel(tab?.id);
@@ -1,7 +1,29 @@
1
1
  'use strict';
2
2
 
3
+ importScripts('messages.js', 'i18n.js');
4
+ const { t } = globalThis.openBrowserI18n;
3
5
  importScripts('workspace-title.js', 'tab-action.js');
4
- globalThis.openBrowserGroupVersion = 12;
6
+ globalThis.openBrowserSetLocale = async settings => {
7
+ await localeReady;
8
+ const changed = globalThis.openBrowserI18n.locale !== settings.locale;
9
+ globalThis.openBrowserI18n.setLocale(settings.locale);
10
+ await chrome.storage.session.set({ interfaceLanguage: settings });
11
+ await chrome.action.setTitle({ title: t('Open Browser Workspace') });
12
+ await chrome.contextMenus.update('workspace-panel', { title: t('Workspace panel') }).catch(() => {});
13
+ if (changed) {
14
+ markFrontTabChanged();
15
+ const slots = await chrome.storage.session.get(null);
16
+ await Promise.all(Object.entries(slots).filter(([key]) => key.startsWith('tab:')).map(([key, previous]) =>
17
+ forWorkspace(previous.workspaceId, async () => {
18
+ const current = (await chrome.storage.session.get(key))[key];
19
+ if (current) await writeAction(current.tabId, current);
20
+ }).catch(() => {})));
21
+ }
22
+ };
23
+ const localeReady = chrome.storage.session.get('interfaceLanguage').then(({interfaceLanguage}) => {
24
+ if (interfaceLanguage) globalThis.openBrowserI18n.setLocale(interfaceLanguage.locale);
25
+ });
26
+ globalThis.openBrowserGroupVersion = 16;
5
27
 
6
28
  const groupsInProgress = new Map();
7
29
 
@@ -111,7 +133,7 @@ globalThis.openBrowserInputHint = async function (pageId) {
111
133
  const record = tab && (await chrome.storage.session.get(tabKey(tab.id)))[tabKey(tab.id)];
112
134
  if (record?.pageId === pageId && record.mode === 'agent') {
113
135
  showRunning(tab.id, false);
114
- await chrome.action.setBadgeText({tabId:tab.id, text:'接管'}).catch(() => {});
136
+ await chrome.action.setBadgeText({tabId:tab.id, text:t("Take")}).catch(() => {});
115
137
  }
116
138
  setTimeout(async () => {
117
139
  if (hint === inputHint) inputHint = null;
@@ -185,8 +207,8 @@ globalThis.openBrowserShow = async function () {
185
207
  return (await chrome.windows.create({ focused: true })).id;
186
208
  };
187
209
 
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']);
210
+ const newtabMethods = new Set(['listWorkspaces', 'listAgentHistory', 'listEvents', 'setInterfaceLanguage']);
211
+ const methods = new Set(['offerCurrentTab','listUploads','grantUpload','revokeUpload','respondDialog','listDownloads','cancelDownload','keepDownload','visualStatus','setPagePixelPermission','listOperations','listEvents', 'listWorkspaces', 'getWorkspace', 'takeControl', 'returnToAgent', 'grantOrigin', 'resolveCredential', 'finishWorkspace']);
190
212
  const pending = new Map();
191
213
  const queued = [];
192
214
  let waiting;
@@ -194,11 +216,11 @@ let waiting;
194
216
  function hostFailure(request) {
195
217
  if (request?.dispatchedAt) return {
196
218
  code: 'host_timeout',
197
- message: 'open-browser 扩展已收到请求,但本机服务未在时限内返回。请检查服务状态后重试。',
219
+ message: t("The extension received the request but the local service timed out. Check the service and try again."),
198
220
  };
199
221
  return {
200
222
  code: 'host_unavailable',
201
- message: 'open-browser 扩展未连接到本机服务,请先启动应用后重试。',
223
+ message: t("The extension is disconnected from the local service. Start Open Browser and try again."),
202
224
  };
203
225
  }
204
226
 
@@ -217,6 +239,8 @@ chrome.runtime.onMessage.addListener((message, sender, respond) => {
217
239
  return false;
218
240
  }
219
241
  const dispatch = async () => {
242
+ if (message.method === 'setInterfaceLanguage')
243
+ return forWorkspace('interfaceLanguage', () => hostRequest(message.method, {preference:message.params.preference}));
220
244
  if (message.method !== 'offerCurrentTab') return hostRequest(message.method, message.params);
221
245
  const {tabId, targetId, origin, workspaceId, accountAlias} = message.params;
222
246
  const [active] = await chrome.tabs.query({active:true,lastFocusedWindow:true});
@@ -224,7 +248,7 @@ chrome.runtime.onMessage.addListener((message, sender, respond) => {
224
248
  const target = (await chrome.debugger.getTargets()).find(t => t.type === 'page' && t.tabId === tabId);
225
249
  if (!target || target.id !== targetId || new URL(target.url).origin !== origin)
226
250
  throw Error('adoption_page_changed');
227
- return hostRequest('offerCurrentTab', {workspaceId, targetId, origin, accountAlias});
251
+ return hostRequest('offerCurrentTab', {workspaceId, targetId, origin, accountAlias, resumeOnRestart:message.params.resumeOnRestart === true, bindOnApproval:message.params.bindOnApproval === true});
228
252
  };
229
253
  dispatch().then(result => respond({ result }), error => respond({ error: error.message }));
230
254
  return true;
@@ -2,9 +2,9 @@
2
2
 
3
3
  function workspaceTitle({ agentName, name, mode }) {
4
4
  const agent = agentName || 'Agent';
5
- const task = typeof name === 'string' && name.trim() ? name.trim() : '未命名任务';
5
+ const task = typeof name === 'string' && name.trim() ? name.trim() : globalThis.openBrowserI18n.t("Untitled task");
6
6
  const title = agent + ' · ' + task;
7
- return mode === 'human' ? '人工 · ' + title : title;
7
+ return mode === 'human' ? globalThis.openBrowserI18n.t("Human · {0}", title) : title;
8
8
  }
9
9
 
10
10
  function workspaceNeedsName({ name }) {