@agentruntime-labs/browser-agent 0.1.0 → 0.2.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 (161) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +6 -0
  3. package/README.md +64 -34
  4. package/bin/browser-agent.js +1 -0
  5. package/cli/control.mjs +477 -0
  6. package/cli/daemon.mjs +143 -0
  7. package/cli/hosts.mjs +1 -0
  8. package/cli/main.mjs +24 -0
  9. package/cli/mcp.mjs +1 -0
  10. package/docs/ARCHITECTURE.md +73 -0
  11. package/docs/DESKTOP_MCP.md +41 -0
  12. package/docs/EXTENSION_MANIFEST.md +163 -0
  13. package/docs/HYBRID.md +12 -0
  14. package/docs/MANAGED_BROWSER.md +111 -0
  15. package/docs/MCP_TOOLS.md +486 -0
  16. package/docs/MESSAGES.md +272 -0
  17. package/docs/MVP.md +76 -0
  18. package/docs/PRIVACY_POLICY.md +50 -0
  19. package/docs/README.md +27 -0
  20. package/docs/REFERENCE_PROJECTS.md +24 -0
  21. package/docs/RELEASE_CHECKLIST.md +49 -0
  22. package/docs/REPEATED_DOCS.md +27 -0
  23. package/docs/SAFETY.md +92 -0
  24. package/docs/SHELL_QUOTING.md +30 -0
  25. package/docs/SPLIT_REPOS.md +46 -0
  26. package/docs/THIRD_PARTY_LICENSES.md +182 -0
  27. package/docs/VISION.md +38 -0
  28. package/docs/WEB_STORE_SUBMISSION.md +117 -0
  29. package/extension/approval.js +1 -0
  30. package/extension/assets/agentruntime-logo.svg +77 -0
  31. package/extension/assets/agentruntime-mark-512.png +0 -0
  32. package/extension/background.js +776 -62
  33. package/extension/cdp.js +577 -0
  34. package/extension/constants.js +1 -0
  35. package/extension/content.js +69 -9
  36. package/extension/devtools-grant.html +31 -0
  37. package/extension/devtools-grant.js +29 -0
  38. package/extension/icons/icon128.png +0 -0
  39. package/extension/icons/icon16.png +0 -0
  40. package/extension/icons/icon32.png +0 -0
  41. package/extension/icons/icon48.png +0 -0
  42. package/extension/manifest.json +50 -23
  43. package/extension/policy.js +102 -0
  44. package/extension/popup.html +190 -56
  45. package/extension/popup.js +376 -166
  46. package/extension/soft.js +301 -0
  47. package/extension/welcome.html +91 -0
  48. package/extension/welcome.js +13 -0
  49. package/package.json +6 -2
  50. package/server/dist/arBrowserPaths.d.ts.map +1 -1
  51. package/server/dist/arBrowserPaths.js +1 -0
  52. package/server/dist/arBrowserPaths.js.map +1 -1
  53. package/server/dist/automationBackend.d.ts +46 -0
  54. package/server/dist/automationBackend.d.ts.map +1 -0
  55. package/server/dist/automationBackend.js +20 -0
  56. package/server/dist/automationBackend.js.map +1 -0
  57. package/server/dist/automationSession.d.ts.map +1 -1
  58. package/server/dist/automationSession.js +1 -0
  59. package/server/dist/automationSession.js.map +1 -1
  60. package/server/dist/bridge.d.ts +17 -4
  61. package/server/dist/bridge.d.ts.map +1 -1
  62. package/server/dist/bridge.js +132 -33
  63. package/server/dist/bridge.js.map +1 -1
  64. package/server/dist/browserToolsExtras.d.ts +2 -2
  65. package/server/dist/browserToolsExtras.d.ts.map +1 -1
  66. package/server/dist/browserToolsExtras.js +70 -1
  67. package/server/dist/browserToolsExtras.js.map +1 -1
  68. package/server/dist/cdpTools.d.ts +5 -0
  69. package/server/dist/cdpTools.d.ts.map +1 -0
  70. package/server/dist/cdpTools.js +411 -0
  71. package/server/dist/cdpTools.js.map +1 -0
  72. package/server/dist/compositeTools.d.ts +2 -2
  73. package/server/dist/compositeTools.d.ts.map +1 -1
  74. package/server/dist/compositeTools.js.map +1 -1
  75. package/server/dist/debugSnapshot.d.ts +2 -2
  76. package/server/dist/debugSnapshot.d.ts.map +1 -1
  77. package/server/dist/debugSnapshot.js.map +1 -1
  78. package/server/dist/guardrails.d.ts.map +1 -1
  79. package/server/dist/guardrails.js +1 -0
  80. package/server/dist/guardrails.js.map +1 -1
  81. package/server/dist/humanLike.d.ts.map +1 -1
  82. package/server/dist/humanLike.js +1 -0
  83. package/server/dist/humanLike.js.map +1 -1
  84. package/server/dist/main.js +56 -15
  85. package/server/dist/main.js.map +1 -1
  86. package/server/dist/managedBridge.d.ts +58 -0
  87. package/server/dist/managedBridge.d.ts.map +1 -0
  88. package/server/dist/managedBridge.js +619 -0
  89. package/server/dist/managedBridge.js.map +1 -0
  90. package/server/dist/managedDom.d.ts +58 -0
  91. package/server/dist/managedDom.d.ts.map +1 -0
  92. package/server/dist/managedDom.js +310 -0
  93. package/server/dist/managedDom.js.map +1 -0
  94. package/server/dist/policyTiers.d.ts.map +1 -1
  95. package/server/dist/policyTiers.js +3 -1
  96. package/server/dist/policyTiers.js.map +1 -1
  97. package/server/dist/protocol.d.ts +4 -0
  98. package/server/dist/protocol.d.ts.map +1 -1
  99. package/server/dist/protocol.js +1 -0
  100. package/server/dist/protocol.js.map +1 -1
  101. package/server/dist/recorder.d.ts +22 -0
  102. package/server/dist/recorder.d.ts.map +1 -0
  103. package/server/dist/recorder.js +82 -0
  104. package/server/dist/recorder.js.map +1 -0
  105. package/server/dist/richEditorFill.d.ts.map +1 -1
  106. package/server/dist/richEditorFill.js +1 -0
  107. package/server/dist/richEditorFill.js.map +1 -1
  108. package/server/dist/screenshotCrop.d.ts.map +1 -1
  109. package/server/dist/screenshotCrop.js +1 -0
  110. package/server/dist/screenshotCrop.js.map +1 -1
  111. package/server/dist/sessionLog.d.ts +1 -0
  112. package/server/dist/sessionLog.d.ts.map +1 -1
  113. package/server/dist/sessionLog.js +1 -0
  114. package/server/dist/sessionLog.js.map +1 -1
  115. package/server/dist/sessionPhase.d.ts.map +1 -1
  116. package/server/dist/sessionPhase.js.map +1 -1
  117. package/server/dist/sessionSummary.d.ts.map +1 -1
  118. package/server/dist/sessionSummary.js +1 -0
  119. package/server/dist/sessionSummary.js.map +1 -1
  120. package/server/dist/shotUtil.d.ts +44 -0
  121. package/server/dist/shotUtil.d.ts.map +1 -0
  122. package/server/dist/shotUtil.js +89 -0
  123. package/server/dist/shotUtil.js.map +1 -0
  124. package/server/dist/skillsInstructions.d.ts.map +1 -1
  125. package/server/dist/skillsInstructions.js +1 -0
  126. package/server/dist/skillsInstructions.js.map +1 -1
  127. package/server/dist/snapshotText.d.ts +47 -0
  128. package/server/dist/snapshotText.d.ts.map +1 -0
  129. package/server/dist/snapshotText.js +99 -0
  130. package/server/dist/snapshotText.js.map +1 -0
  131. package/server/dist/structureFilter.d.ts.map +1 -1
  132. package/server/dist/structureFilter.js.map +1 -1
  133. package/server/dist/surveyCatalog.d.ts.map +1 -1
  134. package/server/dist/surveyCatalog.js +1 -0
  135. package/server/dist/surveyCatalog.js.map +1 -1
  136. package/server/dist/surveyRunner.d.ts.map +1 -1
  137. package/server/dist/surveyRunner.js.map +1 -1
  138. package/server/dist/toolHelpers.d.ts +27 -2
  139. package/server/dist/toolHelpers.d.ts.map +1 -1
  140. package/server/dist/toolHelpers.js +67 -1
  141. package/server/dist/toolHelpers.js.map +1 -1
  142. package/server/dist/toolRuntime.d.ts +4 -0
  143. package/server/dist/toolRuntime.d.ts.map +1 -1
  144. package/server/dist/toolRuntime.js +12 -6
  145. package/server/dist/toolRuntime.js.map +1 -1
  146. package/server/dist/toolSchemas.d.ts +37 -1
  147. package/server/dist/toolSchemas.d.ts.map +1 -1
  148. package/server/dist/toolSchemas.js +33 -1
  149. package/server/dist/toolSchemas.js.map +1 -1
  150. package/server/dist/tools.d.ts +2 -2
  151. package/server/dist/tools.d.ts.map +1 -1
  152. package/server/dist/tools.js +65 -11
  153. package/server/dist/tools.js.map +1 -1
  154. package/server/dist/verdictExtract.d.ts.map +1 -1
  155. package/server/dist/verdictExtract.js +1 -0
  156. package/server/dist/verdictExtract.js.map +1 -1
  157. package/server/dist/workflowTools.d.ts +2 -2
  158. package/server/dist/workflowTools.d.ts.map +1 -1
  159. package/server/dist/workflowTools.js +16 -4
  160. package/server/dist/workflowTools.js.map +1 -1
  161. package/skills/browser-agent/SKILL.md +89 -0
@@ -1,13 +1,14 @@
1
+ // SPDX-License-Identifier: Apache-2.0
1
2
  /**
2
- * Browser Automation — content script (isolated world).
3
+ * AgentRuntime Browser Agent — content script (isolated world).
3
4
  * Injected programmatically; guard prevents duplicate listeners on re-inject.
4
5
  */
5
6
  // @ts-nocheck
6
7
 
7
- if (globalThis.__BROWSER_AUTOMATION_CS_V4__) {
8
+ if (globalThis.__BROWSER_AUTOMATION_CS_V5__) {
8
9
  /* already armed */
9
10
  } else {
10
- globalThis.__BROWSER_AUTOMATION_CS_V4__ = true;
11
+ globalThis.__BROWSER_AUTOMATION_CS_V5__ = true;
11
12
 
12
13
  const SUBMIT_BUTTON_RE = /\b(submit|post|send|publish|save|continue|reply|tweet)\b/i;
13
14
 
@@ -62,8 +63,33 @@ if (globalThis.__BROWSER_AUTOMATION_CS_V4__) {
62
63
  return false;
63
64
  }
64
65
 
66
+ /** Shadow root of el: open roots directly; closed roots too via the extension-only chrome.dom API. */
67
+ function shadowRootOf(el) {
68
+ try {
69
+ return (
70
+ (typeof chrome !== 'undefined' && chrome.dom?.openOrClosedShadowRoot?.(el)) ||
71
+ el.shadowRoot ||
72
+ null
73
+ );
74
+ } catch {
75
+ return el.shadowRoot || null;
76
+ }
77
+ }
78
+
79
+ /** All elements in document order, descending into shadow roots (document.querySelectorAll does not). */
80
+ function deepQueryAll(root = document, out = []) {
81
+ for (const el of root.querySelectorAll('*')) {
82
+ out.push(el);
83
+ const sr = shadowRootOf(el);
84
+ if (sr) {
85
+ deepQueryAll(sr, out);
86
+ }
87
+ }
88
+ return out;
89
+ }
90
+
65
91
  function getFocusableElements() {
66
- const all = document.querySelectorAll('*');
92
+ const all = deepQueryAll();
67
93
  const out = [];
68
94
  for (const el of all) {
69
95
  if (isFocusable(el)) {
@@ -169,6 +195,15 @@ if (globalThis.__BROWSER_AUTOMATION_CS_V4__) {
169
195
  return 'Empty structure — wait for load or check tab URL.';
170
196
  }
171
197
 
198
+ function visibleLabelText(el) {
199
+ try {
200
+ const l = el.labels && el.labels[0];
201
+ return l ? (l.textContent || '').replace(/\s+/g, ' ').trim().slice(0, 120) : '';
202
+ } catch {
203
+ return '';
204
+ }
205
+ }
206
+
172
207
  function elementLabel(el) {
173
208
  const tag = el.tagName.toLowerCase();
174
209
  if (el instanceof HTMLInputElement) {
@@ -179,6 +214,7 @@ if (globalThis.__BROWSER_AUTOMATION_CS_V4__) {
179
214
  }
180
215
  bits.push(
181
216
  el.getAttribute('aria-label'),
217
+ t === 'submit' || t === 'button' || t === 'reset' ? '' : visibleLabelText(el),
182
218
  el.placeholder,
183
219
  t !== 'text' && t !== 'search' ? `[${t}]` : '',
184
220
  el.name,
@@ -210,6 +246,7 @@ if (globalThis.__BROWSER_AUTOMATION_CS_V4__) {
210
246
  const opt = el.selectedIndex >= 0 ? el.options[el.selectedIndex] : null;
211
247
  return (
212
248
  el.getAttribute('aria-label') ||
249
+ visibleLabelText(el) ||
213
250
  el.name ||
214
251
  el.id ||
215
252
  (opt ? opt.text?.trim() : '') ||
@@ -218,7 +255,7 @@ if (globalThis.__BROWSER_AUTOMATION_CS_V4__) {
218
255
  }
219
256
  if (el instanceof HTMLTextAreaElement) {
220
257
  return (
221
- el.getAttribute('aria-label') || el.placeholder || el.name || el.id || ''
258
+ el.getAttribute('aria-label') || visibleLabelText(el) || el.placeholder || el.name || el.id || ''
222
259
  ).slice(0, 220);
223
260
  }
224
261
  return (
@@ -331,7 +368,7 @@ if (globalThis.__BROWSER_AUTOMATION_CS_V4__) {
331
368
  skippedSkipLink: 0,
332
369
  emitted: 0
333
370
  };
334
- const all = document.querySelectorAll('*');
371
+ const all = deepQueryAll();
335
372
  let n = 0;
336
373
  for (const el of all) {
337
374
  const hiddenFile = isHiddenFileInput(el);
@@ -383,8 +420,16 @@ if (globalThis.__BROWSER_AUTOMATION_CS_V4__) {
383
420
  name: name.slice(0, 300),
384
421
  tag,
385
422
  inputType: tag === 'input' ? inputType : tag === 'textarea' ? 'textarea' : undefined,
386
- hint: label ? label.slice(0, 300) : undefined,
423
+ hint: hiddenFile
424
+ ? (label ? label.slice(0, 300) : 'file upload') + ' [hidden file input]'
425
+ : label
426
+ ? label.slice(0, 300)
427
+ : undefined,
387
428
  disabled: el instanceof HTMLButtonElement || el instanceof HTMLInputElement ? el.disabled : false,
429
+ frameSrc:
430
+ el instanceof HTMLIFrameElement
431
+ ? el.src || (el.hasAttribute('srcdoc') ? 'about:srcdoc' : '')
432
+ : undefined,
388
433
  rect
389
434
  });
390
435
  stats.emitted += 1;
@@ -399,7 +444,7 @@ if (globalThis.__BROWSER_AUTOMATION_CS_V4__) {
399
444
  fileSeen.add(mapped);
400
445
  }
401
446
  }
402
- for (const el of document.querySelectorAll('input[type=file]')) {
447
+ for (const el of all.filter((x) => x instanceof HTMLInputElement && x.type === 'file')) {
403
448
  if (fileSeen.has(el)) {
404
449
  continue;
405
450
  }
@@ -444,7 +489,22 @@ if (globalThis.__BROWSER_AUTOMATION_CS_V4__) {
444
489
  }
445
490
 
446
491
  function getPageText(maxChars) {
447
- const t = document.body?.innerText ?? '';
492
+ // innerText does not cross shadow boundaries: append text of every shadow root.
493
+ const parts = [document.body?.innerText ?? ''];
494
+ for (const el of deepQueryAll()) {
495
+ const sr = shadowRootOf(el);
496
+ if (sr) {
497
+ const st = Array.from(sr.children)
498
+ .map((c) => c.innerText ?? '')
499
+ .filter((s) => s.trim())
500
+ .join('\n')
501
+ .trim();
502
+ if (st) {
503
+ parts.push(st);
504
+ }
505
+ }
506
+ }
507
+ const t = parts.filter((s) => s.trim()).join('\n');
448
508
  const truncated = t.length > maxChars;
449
509
  return { text: t.slice(0, maxChars), truncated, length: t.length };
450
510
  }
@@ -0,0 +1,31 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>Allow DevTools access</title>
6
+ <style>
7
+ body { font: 15px system-ui, sans-serif; margin: 0; padding: 20px; min-height: 100vh; box-sizing: border-box; background: #fff; color: #111; }
8
+ h1 { font-size: 16px; margin: 0 0 8px; }
9
+ p { margin: 6px 0; color: #333; line-height: 1.4; }
10
+ .row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
11
+ button { font: inherit; padding: 10px 22px; font-weight: 600; border-radius: 6px; border: 1px solid #bbb; background: #f4f4f4; cursor: pointer; }
12
+ button.primary { background: #111; color: #fff; border-color: #111; }
13
+ small { color: #666; }
14
+ @media (prefers-color-scheme: dark) {
15
+ body { background: #1b1b1b; color: #eee; } p { color: #ccc; } small { color: #999; }
16
+ button { background: #2a2a2a; color: #eee; border-color: #555; } button.primary { background: #eee; color: #111; }
17
+ }
18
+ </style>
19
+ </head>
20
+ <body>
21
+ <h1>A tool needs Chrome DevTools access</h1>
22
+ <p id="why">An automation request needs a feature that only works through Chrome DevTools.</p>
23
+ <p><small>Chrome shows its "started debugging this browser" bar only while a call runs. You can turn it off at any time in the extension popup.</small></p>
24
+ <div class="row">
25
+ <button id="allow" class="primary">Allow for 10 minutes</button>
26
+ <button id="allowAlways">Allow until I turn it off</button>
27
+ <button id="deny">Not now</button>
28
+ </div>
29
+ <script src="devtools-grant.js"></script>
30
+ </body>
31
+ </html>
@@ -0,0 +1,29 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // One-click grant page: a click here is the user gesture Chrome requires for an optional permission.
3
+ async function finish(granted) {
4
+ try {
5
+ await chrome.runtime.sendMessage({ type: 'devtools-grant-result', granted });
6
+ } catch {
7
+ /* background may already have closed this window */
8
+ }
9
+ window.close();
10
+ }
11
+
12
+ // Chrome cannot grant `debugger` at run time, so this extension keeps its own switch (see cdp.js enabled()).
13
+ document.getElementById('allow').onclick = async () => {
14
+ await chrome.storage.local.set({ devtoolsUntil: Date.now() + 10 * 60 * 1000 });
15
+ await finish(true);
16
+ };
17
+ document.getElementById('allowAlways').onclick = async () => {
18
+ await chrome.storage.local.set({ devtoolsMode: 'always' });
19
+ await finish(true);
20
+ };
21
+ document.getElementById('deny').onclick = () => finish(false);
22
+
23
+ // Enter allows, Escape denies; the Allow button gets focus so a keypress is enough.
24
+ document.getElementById('allow').focus();
25
+ document.addEventListener('keydown', (e) => {
26
+ if (e.key === 'Escape') {
27
+ void finish(false);
28
+ }
29
+ });
Binary file
Binary file
Binary file
Binary file
@@ -1,23 +1,50 @@
1
- {
2
- "manifest_version": 3,
3
- "name": "Browser Automation Connector",
4
- "version": "0.1.0",
5
- "description": "Local MCP bridge: connects your real browser tab to the browser-automation server (localhost).",
6
- "minimum_chrome_version": "114",
7
- "action": {
8
- "default_title": "Browser Automation",
9
- "default_popup": "popup.html"
10
- },
11
- "background": {
12
- "service_worker": "background.js",
13
- "type": "module"
14
- },
15
- "permissions": ["storage", "scripting", "tabs", "activeTab", "webRequest"],
16
- "host_permissions": ["<all_urls>"],
17
- "web_accessible_resources": [
18
- {
19
- "resources": ["approval.html", "approval.js"],
20
- "matches": ["chrome-extension://*/*"]
21
- }
22
- ]
23
- }
1
+ {
2
+ "manifest_version": 3,
3
+ "name": "AgentRuntime Browser Agent",
4
+ "version": "0.9.1",
5
+ "description": "Lets the AI agents you run on your own computer work in your browser tabs, through a local connection only.",
6
+ "minimum_chrome_version": "114",
7
+ "action": {
8
+ "default_title": "AgentRuntime Browser Agent",
9
+ "default_popup": "popup.html",
10
+ "default_icon": {
11
+ "16": "icons/icon16.png",
12
+ "32": "icons/icon32.png"
13
+ }
14
+ },
15
+ "background": {
16
+ "service_worker": "background.js",
17
+ "type": "module"
18
+ },
19
+ "permissions": [
20
+ "storage",
21
+ "scripting",
22
+ "tabs",
23
+ "activeTab",
24
+ "webRequest",
25
+ "downloads",
26
+ "alarms",
27
+ "debugger"
28
+ ],
29
+ "host_permissions": [
30
+ "<all_urls>"
31
+ ],
32
+ "web_accessible_resources": [
33
+ {
34
+ "resources": [
35
+ "approval.html",
36
+ "approval.js"
37
+ ],
38
+ "matches": [
39
+ "chrome-extension://*/*"
40
+ ]
41
+ }
42
+ ],
43
+ "icons": {
44
+ "16": "icons/icon16.png",
45
+ "32": "icons/icon32.png",
46
+ "48": "icons/icon48.png",
47
+ "128": "icons/icon128.png"
48
+ },
49
+ "short_name": "AR Browser"
50
+ }
@@ -0,0 +1,102 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ /**
3
+ * Tab policy: which tabs an agent may use. Pure functions, no Chrome APIs, so the rules can be unit-tested.
4
+ *
5
+ * Modes (chosen by the user in the popup; no agent tool can change them):
6
+ * freeform agents may use any tab: open, switch, close tabs, open windows.
7
+ * follow agents may use only the tab the user is on (it moves when the user switches tabs).
8
+ * pinned agents may use only the pinned tabs (one or several). The pin is the lock.
9
+ *
10
+ * In follow and pinned mode, opening tabs or windows, moving or focusing windows, and any call that names a tab
11
+ * outside the allowed set are refused, and tab or window lists show only allowed tabs.
12
+ */
13
+
14
+ export const MODES = ['freeform', 'follow', 'pinned'];
15
+
16
+ /** Calls refused outright when the mode is not freeform (they create or move things outside the allowed tabs). */
17
+ export const BLOCKED_WHEN_RESTRICTED = new Set(['tab_open', 'window_open', 'window_resize', 'window_focus']);
18
+
19
+ /** Map stored values (including older versions) to a mode. */
20
+ export function normalizeMode(stored, legacyPinnedTabId) {
21
+ if (stored === 'freeform' || stored === 'follow' || stored === 'pinned') return stored;
22
+ if (stored === 'agent') return 'freeform';
23
+ if (stored === 'front') return 'follow';
24
+ return legacyPinnedTabId != null ? 'pinned' : 'freeform'; // default: agents may use any tab
25
+ }
26
+
27
+ function blocked(message) {
28
+ return { error: { code: 'tab_not_allowed', message } };
29
+ }
30
+
31
+ /** One line for agents: what this mode lets them do. */
32
+ export function modeSummary(mode) {
33
+ if (mode === 'freeform') return 'any tab: you may open, switch and close tabs and open windows';
34
+ if (mode === 'follow') return 'only the tab the user is on (it changes when the user switches tabs); you cannot open or touch other tabs';
35
+ return 'only the tabs the user pinned; you cannot open or touch other tabs';
36
+ }
37
+
38
+ export function describeMode(mode) {
39
+ return mode === 'follow'
40
+ ? 'Follow mode: agents may only use the tab the user is on.'
41
+ : 'Pinned mode: agents may only use the pinned tabs.';
42
+ }
43
+
44
+ const HOW_TO_FIX = ' Ask the user to change the tab mode (or pin this tab) in the extension popup.';
45
+
46
+ /**
47
+ * Decide the tab for a call.
48
+ * @param {{mode: string, pinned: number[], front: number|null, lastUsedPinned?: number|null,
49
+ * requested?: number|null, fromAgentDefault?: boolean}} a
50
+ * @returns {{tabId: number|null}|{error: {code: string, message: string}}}
51
+ * tabId null means "no restriction and nothing chosen": the caller falls back to the front tab (freeform only).
52
+ */
53
+ export function resolveTarget(a) {
54
+ const requested = Number.isFinite(a.requested) ? a.requested : null;
55
+ const explicit = requested !== null && a.fromAgentDefault !== true;
56
+
57
+ if (a.mode === 'freeform') {
58
+ return { tabId: requested };
59
+ }
60
+
61
+ if (a.mode === 'follow') {
62
+ if (a.front == null) return blocked('Follow mode: there is no tab in front to work on.');
63
+ if (explicit && requested !== a.front) {
64
+ return blocked(`${describeMode('follow')} Tab ${requested} is not the tab in front (${a.front}).${HOW_TO_FIX}`);
65
+ }
66
+ return { tabId: a.front };
67
+ }
68
+
69
+ // pinned
70
+ const pinned = a.pinned ?? [];
71
+ if (pinned.length === 0) {
72
+ return blocked('Pinned mode: no tab is pinned yet. Ask the user to pin a tab in the extension popup.');
73
+ }
74
+ if (explicit) {
75
+ if (!pinned.includes(requested)) {
76
+ return blocked(`${describeMode('pinned')} Tab ${requested} is not pinned (pinned: ${pinned.join(', ')}).${HOW_TO_FIX}`);
77
+ }
78
+ return { tabId: requested };
79
+ }
80
+ if (requested !== null && pinned.includes(requested)) {
81
+ return { tabId: requested }; // the agent's own default tab, if it is inside the pinned set
82
+ }
83
+ if (a.lastUsedPinned != null && pinned.includes(a.lastUsedPinned)) {
84
+ return { tabId: a.lastUsedPinned };
85
+ }
86
+ return { tabId: pinned[0] };
87
+ }
88
+
89
+ /** Set of tab ids an agent may see and use right now, or null when everything is allowed. */
90
+ export function allowedSet(mode, pinned, front) {
91
+ if (mode === 'freeform') return null;
92
+ if (mode === 'follow') return new Set(front == null ? [] : [front]);
93
+ return new Set(pinned ?? []);
94
+ }
95
+
96
+ /** Why a non-tab call is refused in a restricted mode, or null if it may run. */
97
+ export function blockedOp(mode, op) {
98
+ if (mode !== 'freeform' && BLOCKED_WHEN_RESTRICTED.has(op)) {
99
+ return `${describeMode(mode)} Opening or moving tabs and windows is not allowed.${HOW_TO_FIX}`;
100
+ }
101
+ return null;
102
+ }
@@ -1,56 +1,190 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <title>Connect — Browser Automation</title>
6
- <style>
7
- body {
8
- font-family: system-ui, sans-serif;
9
- margin: 12px;
10
- min-width: 280px;
11
- }
12
- label {
13
- display: block;
14
- margin-top: 8px;
15
- font-size: 12px;
16
- }
17
- input {
18
- width: 100%;
19
- box-sizing: border-box;
20
- margin-top: 4px;
21
- }
22
- button {
23
- margin-top: 10px;
24
- width: 100%;
25
- padding: 8px;
26
- }
27
- .status {
28
- margin-top: 8px;
29
- font-size: 12px;
30
- color: #333;
31
- }
32
- .err {
33
- color: #b00020;
34
- }
35
- .ok {
36
- color: #0a6;
37
- }
38
- </style>
39
- </head>
40
- <body>
41
- <h3 style="margin: 0 0 8px">Browser Automation</h3>
42
- <label>WebSocket port <input id="port" type="number" value="18791" /></label>
43
- <label
44
- >Session token (from server stderr)
45
- <input id="token" type="password" autocomplete="off" placeholder="SESSION=..."
46
- /></label>
47
- <button id="connect">Connect to server</button>
48
- <button id="disconnect" type="button">Disconnect</button>
49
- <button id="setTab" type="button">Pin this tab (optional)</button>
50
- <button id="clearPin" type="button">Use active tab (default)</button>
51
- <button id="copyPairing" type="button">Copy pairing info (port + token)</button>
52
- <button id="copyMcpSnippet" type="button">Copy Cursor MCP config snippet</button>
53
- <div id="status" class="status"></div>
54
- <script type="module" src="popup.js"></script>
55
- </body>
56
- </html>
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <title>AgentRuntime Browser Agent</title>
6
+ <style>
7
+ :root {
8
+ --bg: #ffffff;
9
+ --card: #ffffff;
10
+ --text: #0f172a;
11
+ --muted: #475569;
12
+ --line: #e2e8f0;
13
+ --accent: #0f172a;
14
+ --accent-text: #ffffff;
15
+ --soft: #f1f5f9;
16
+ --ok: #16a34a;
17
+ --err: #b91c1c;
18
+ --field: #ffffff;
19
+ }
20
+ @media (prefers-color-scheme: dark) {
21
+ :root {
22
+ --bg: #0a0a0b;
23
+ --card: #111113;
24
+ --text: #f4f4f5;
25
+ --muted: #bcbcc6;
26
+ --line: #3a3a40;
27
+ --accent: #fafafa;
28
+ --accent-text: #0a0a0b;
29
+ --soft: #18181b;
30
+ --ok: #4ade80;
31
+ --err: #f87171;
32
+ --field: #0a0a0b;
33
+ }
34
+ }
35
+ * { box-sizing: border-box; }
36
+ [hidden] { display: none !important; }
37
+ body {
38
+ font: 13px/1.45 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
39
+ margin: 0;
40
+ width: 360px;
41
+ background: var(--bg);
42
+ color: var(--text);
43
+ }
44
+ header {
45
+ display: flex; align-items: center; justify-content: space-between;
46
+ padding: 12px 14px 10px; border-bottom: 1px solid var(--line); margin-bottom: 10px;
47
+ }
48
+ .brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
49
+ .logo { width: 30px; height: 30px; flex: none; }
50
+ @media (prefers-color-scheme: dark) { .logo { filter: invert(1); } }
51
+ h1 { font-size: 14px; margin: 0; letter-spacing: 0; line-height: 1.2; min-width: 0; }
52
+ header { gap: 8px; }
53
+ .ver { display: block; color: var(--muted); font-size: 11px; font-weight: 400; }
54
+ .pill {
55
+ display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600;
56
+ padding: 3px 10px; border-radius: 999px; white-space: nowrap; flex: none; border: 1px solid var(--line); color: var(--muted); background: var(--card);
57
+ }
58
+ .pill.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
59
+ .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
60
+ .pill.on .dot { background: var(--ok); }
61
+ main { padding: 0 12px 12px; display: grid; gap: 8px; }
62
+ section {
63
+ background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px;
64
+ }
65
+ h2 { font-size: 10.5px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); margin: 0 0 8px; font-weight: 700; }
66
+ .row { display: flex; gap: 8px; align-items: center; }
67
+ .row > .grow { flex: 1; min-width: 0; }
68
+ input[type=text], input[type=number], input[type=password] {
69
+ width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px;
70
+ background: var(--field); color: var(--text); font: inherit;
71
+ }
72
+ input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
73
+ button {
74
+ font: inherit; font-weight: 600; padding: 7px 12px; border-radius: 7px; cursor: pointer;
75
+ border: 1px solid var(--line); background: var(--card); color: var(--text);
76
+ }
77
+ button:hover { background: var(--soft); }
78
+ button.primary:hover { background: var(--accent); opacity: .88; }
79
+ button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
80
+ button.small { padding: 5px 9px; font-size: 12px; }
81
+ .hint { color: var(--muted); font-size: 12px; margin-top: 6px; }
82
+ .conn-title { font-weight: 700; font-size: 14px; }
83
+ .cmdbox { display:block; margin: 8px 0 2px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--soft); font: 12px ui-monospace, Consolas, monospace; overflow-x: auto; white-space: nowrap; user-select: all; }
84
+ .conn-title + .hint { margin-top: 2px; margin-bottom: 8px; }
85
+ .id { font-family: ui-monospace, Consolas, monospace; font-size: 11px; color: var(--muted); }
86
+ .agents { display: grid; gap: 4px; margin-bottom: 8px; }
87
+ .agent { display: flex; justify-content: space-between; font-size: 12px; padding: 6px 8px; border-radius: 6px; background: var(--soft); }
88
+ .agent span:last-child { color: var(--muted); }
89
+ .seg { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
90
+ .seg button { flex: 1; border: 0; border-radius: 0; background: transparent; font-weight: 500; }
91
+ .seg button:hover { background: var(--soft); }
92
+ .seg button.active, .seg button.active:hover { background: var(--accent); color: var(--accent-text); font-weight: 600; }
93
+ .switch { position: relative; width: 38px; height: 22px; flex: none; }
94
+ .switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; z-index: 1; }
95
+ .track { position: absolute; inset: 0; border-radius: 999px; background: var(--line); border: 1px solid var(--line); transition: background .15s; }
96
+ .track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--card); box-shadow: 0 0 0 1px var(--line); transition: transform .15s; }
97
+ .switch input:checked + .track { background: var(--accent); }
98
+ .switch input:checked + .track::after { transform: translateX(16px); }
99
+ label.check { display: flex; gap: 8px; align-items: center; font-size: 12px; margin-top: 8px; }
100
+ details { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
101
+ summary { cursor: pointer; font-weight: 600; font-size: 12px; color: var(--muted); }
102
+ details[open] summary { margin-bottom: 8px; }
103
+ .stack { display: grid; gap: 8px; }
104
+ .fieldlabel { font-size: 12px; color: var(--muted); display: block; margin-bottom: 3px; }
105
+ #status { min-height: 18px; font-size: 12px; color: var(--muted); padding: 0 2px; }
106
+ #status.ok { color: var(--ok); }
107
+ #status.err { color: var(--err); }
108
+ </style>
109
+ </head>
110
+ <body>
111
+ <header>
112
+ <div class="brand"><img class="logo" src="assets/agentruntime-logo.svg" alt="AgentRuntime" /><h1>AgentRuntime Browser Agent<span class="ver" id="ver"></span></h1></div>
113
+ <span class="pill" id="pill"><span class="dot"></span><span id="pillText">Not connected</span></span>
114
+ </header>
115
+
116
+ <main>
117
+ <section>
118
+ <h2>Connection</h2>
119
+ <div class="conn-title" id="connTitle"></div>
120
+ <div class="hint" id="connText"></div>
121
+ <code class="cmdbox" id="cmdBox" hidden></code>
122
+ <div class="agents" id="agents"></div>
123
+ <div class="row" id="connActions"></div>
124
+ <div class="hint" id="connMore"></div>
125
+ <button id="connect" type="button" hidden>Connect</button>
126
+ <button id="disconnect" type="button" hidden>Disconnect</button>
127
+ </section>
128
+
129
+ <section>
130
+ <h2>This Chrome profile</h2>
131
+ <div class="row">
132
+ <div class="grow"><input id="label" type="text" maxlength="60" placeholder="Name this profile" aria-label="Profile name" /></div>
133
+ <button id="saveLabel" class="primary" type="button">Save</button>
134
+ </div>
135
+ <div class="hint" id="labelHint"></div>
136
+ <div class="hint"><span class="id" id="instanceId"></span></div>
137
+ </section>
138
+
139
+ <section>
140
+ <h2>Which tabs agents can use</h2>
141
+ <div class="seg" id="tabMode">
142
+ <button id="modeFreeform" type="button">Freeform</button>
143
+ <button id="modeFollow" type="button">Follow</button>
144
+ <button id="modePinned" type="button">Pinned</button>
145
+ </div>
146
+ <div class="hint" id="modeHelp"></div>
147
+ <div id="pinBox" hidden>
148
+ <div class="agents" id="pinList"></div>
149
+ <button id="pinThis" class="small" type="button">Pin this tab</button>
150
+ </div>
151
+ <div class="hint" id="tabLive"></div>
152
+ </section>
153
+
154
+ <section>
155
+ <h2>Chrome DevTools features</h2>
156
+ <div class="row">
157
+ <div class="grow"><strong>Allow DevTools access</strong>
158
+ <div class="hint" style="margin-top:2px" id="devtoolsNote"></div></div>
159
+ <label class="switch" title="Allow or remove the debugger permission">
160
+ <input id="devtools" type="checkbox" aria-label="Allow DevTools access" /><span class="track"></span>
161
+ </label>
162
+ </div>
163
+ <label class="check"><input id="autoDevtools" type="checkbox" checked /> Ask me when a tool needs it</label>
164
+ </section>
165
+
166
+ <details>
167
+ <summary>Advanced</summary>
168
+ <div class="stack">
169
+ <div>
170
+ <span class="fieldlabel">WebSocket port (start of the scan range)</span>
171
+ <input id="port" type="number" value="18791" />
172
+ </div>
173
+ <div>
174
+ <span class="fieldlabel">Session token (blank for the standard install)</span>
175
+ <input id="token" type="password" autocomplete="off" placeholder="SESSION=..." />
176
+ </div>
177
+ <label class="check" style="margin-top:0"><input id="allowEval" type="checkbox" /> Allow page script evaluation (browser_evaluate). Off by default.</label>
178
+ <div class="row">
179
+ <button id="copyPairing" class="small" type="button">Copy pairing info</button>
180
+ <button id="copyMcpSnippet" class="small" type="button">Copy Cursor config</button>
181
+ </div>
182
+ </div>
183
+ </details>
184
+
185
+ <div class="hint"><a href="#" id="openGuide">Setup guide</a> &middot; More from AgentRuntime: <a href="https://agentruntime.io" target="_blank" rel="noopener">AgentRuntime</a>, <a href="https://github.com/agentruntime-io/desktop-agent" target="_blank" rel="noopener">Desktop Agent</a></div>
186
+ <div id="status"></div>
187
+ </main>
188
+ <script type="module" src="popup.js"></script>
189
+ </body>
190
+ </html>