@agentruntime-labs/browser-agent 0.1.1 → 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.
- package/LICENSE +202 -0
- package/NOTICE +6 -0
- package/README.md +64 -34
- package/bin/browser-agent.js +1 -0
- package/cli/control.mjs +477 -0
- package/cli/daemon.mjs +143 -0
- package/cli/hosts.mjs +1 -0
- package/cli/main.mjs +24 -0
- package/cli/mcp.mjs +1 -0
- package/docs/ARCHITECTURE.md +73 -0
- package/docs/DESKTOP_MCP.md +41 -0
- package/docs/EXTENSION_MANIFEST.md +163 -0
- package/docs/HYBRID.md +12 -0
- package/docs/MANAGED_BROWSER.md +111 -0
- package/docs/MCP_TOOLS.md +486 -0
- package/docs/MESSAGES.md +272 -0
- package/docs/MVP.md +76 -0
- package/docs/PRIVACY_POLICY.md +50 -0
- package/docs/README.md +27 -0
- package/docs/REFERENCE_PROJECTS.md +24 -0
- package/docs/RELEASE_CHECKLIST.md +49 -0
- package/docs/REPEATED_DOCS.md +27 -0
- package/docs/SAFETY.md +92 -0
- package/docs/SHELL_QUOTING.md +30 -0
- package/docs/SPLIT_REPOS.md +46 -0
- package/docs/THIRD_PARTY_LICENSES.md +182 -0
- package/docs/VISION.md +38 -0
- package/docs/WEB_STORE_SUBMISSION.md +117 -0
- package/extension/approval.js +1 -0
- package/extension/assets/agentruntime-logo.svg +77 -0
- package/extension/assets/agentruntime-mark-512.png +0 -0
- package/extension/background.js +776 -62
- package/extension/cdp.js +577 -0
- package/extension/constants.js +1 -0
- package/extension/content.js +69 -9
- package/extension/devtools-grant.html +31 -0
- package/extension/devtools-grant.js +29 -0
- package/extension/icons/icon128.png +0 -0
- package/extension/icons/icon16.png +0 -0
- package/extension/icons/icon32.png +0 -0
- package/extension/icons/icon48.png +0 -0
- package/extension/manifest.json +50 -23
- package/extension/policy.js +102 -0
- package/extension/popup.html +190 -56
- package/extension/popup.js +376 -166
- package/extension/soft.js +301 -0
- package/extension/welcome.html +91 -0
- package/extension/welcome.js +13 -0
- package/package.json +6 -2
- package/server/dist/arBrowserPaths.d.ts.map +1 -1
- package/server/dist/arBrowserPaths.js +1 -0
- package/server/dist/arBrowserPaths.js.map +1 -1
- package/server/dist/automationBackend.d.ts +46 -0
- package/server/dist/automationBackend.d.ts.map +1 -0
- package/server/dist/automationBackend.js +20 -0
- package/server/dist/automationBackend.js.map +1 -0
- package/server/dist/automationSession.d.ts.map +1 -1
- package/server/dist/automationSession.js +1 -0
- package/server/dist/automationSession.js.map +1 -1
- package/server/dist/bridge.d.ts +17 -4
- package/server/dist/bridge.d.ts.map +1 -1
- package/server/dist/bridge.js +132 -33
- package/server/dist/bridge.js.map +1 -1
- package/server/dist/browserToolsExtras.d.ts +2 -2
- package/server/dist/browserToolsExtras.d.ts.map +1 -1
- package/server/dist/browserToolsExtras.js +70 -1
- package/server/dist/browserToolsExtras.js.map +1 -1
- package/server/dist/cdpTools.d.ts +5 -0
- package/server/dist/cdpTools.d.ts.map +1 -0
- package/server/dist/cdpTools.js +411 -0
- package/server/dist/cdpTools.js.map +1 -0
- package/server/dist/compositeTools.d.ts +2 -2
- package/server/dist/compositeTools.d.ts.map +1 -1
- package/server/dist/compositeTools.js.map +1 -1
- package/server/dist/debugSnapshot.d.ts +2 -2
- package/server/dist/debugSnapshot.d.ts.map +1 -1
- package/server/dist/debugSnapshot.js.map +1 -1
- package/server/dist/guardrails.d.ts.map +1 -1
- package/server/dist/guardrails.js +1 -0
- package/server/dist/guardrails.js.map +1 -1
- package/server/dist/humanLike.d.ts.map +1 -1
- package/server/dist/humanLike.js +1 -0
- package/server/dist/humanLike.js.map +1 -1
- package/server/dist/main.js +56 -15
- package/server/dist/main.js.map +1 -1
- package/server/dist/managedBridge.d.ts +58 -0
- package/server/dist/managedBridge.d.ts.map +1 -0
- package/server/dist/managedBridge.js +619 -0
- package/server/dist/managedBridge.js.map +1 -0
- package/server/dist/managedDom.d.ts +58 -0
- package/server/dist/managedDom.d.ts.map +1 -0
- package/server/dist/managedDom.js +310 -0
- package/server/dist/managedDom.js.map +1 -0
- package/server/dist/policyTiers.d.ts.map +1 -1
- package/server/dist/policyTiers.js +3 -1
- package/server/dist/policyTiers.js.map +1 -1
- package/server/dist/protocol.d.ts +4 -0
- package/server/dist/protocol.d.ts.map +1 -1
- package/server/dist/protocol.js +1 -0
- package/server/dist/protocol.js.map +1 -1
- package/server/dist/recorder.d.ts +22 -0
- package/server/dist/recorder.d.ts.map +1 -0
- package/server/dist/recorder.js +82 -0
- package/server/dist/recorder.js.map +1 -0
- package/server/dist/richEditorFill.d.ts.map +1 -1
- package/server/dist/richEditorFill.js +1 -0
- package/server/dist/richEditorFill.js.map +1 -1
- package/server/dist/screenshotCrop.d.ts.map +1 -1
- package/server/dist/screenshotCrop.js +1 -0
- package/server/dist/screenshotCrop.js.map +1 -1
- package/server/dist/sessionLog.d.ts +1 -0
- package/server/dist/sessionLog.d.ts.map +1 -1
- package/server/dist/sessionLog.js +1 -0
- package/server/dist/sessionLog.js.map +1 -1
- package/server/dist/sessionPhase.d.ts.map +1 -1
- package/server/dist/sessionPhase.js.map +1 -1
- package/server/dist/sessionSummary.d.ts.map +1 -1
- package/server/dist/sessionSummary.js +1 -0
- package/server/dist/sessionSummary.js.map +1 -1
- package/server/dist/shotUtil.d.ts +44 -0
- package/server/dist/shotUtil.d.ts.map +1 -0
- package/server/dist/shotUtil.js +89 -0
- package/server/dist/shotUtil.js.map +1 -0
- package/server/dist/skillsInstructions.d.ts.map +1 -1
- package/server/dist/skillsInstructions.js +1 -0
- package/server/dist/skillsInstructions.js.map +1 -1
- package/server/dist/snapshotText.d.ts +47 -0
- package/server/dist/snapshotText.d.ts.map +1 -0
- package/server/dist/snapshotText.js +99 -0
- package/server/dist/snapshotText.js.map +1 -0
- package/server/dist/structureFilter.d.ts.map +1 -1
- package/server/dist/structureFilter.js.map +1 -1
- package/server/dist/surveyCatalog.d.ts.map +1 -1
- package/server/dist/surveyCatalog.js +1 -0
- package/server/dist/surveyCatalog.js.map +1 -1
- package/server/dist/surveyRunner.d.ts.map +1 -1
- package/server/dist/surveyRunner.js.map +1 -1
- package/server/dist/toolHelpers.d.ts +27 -2
- package/server/dist/toolHelpers.d.ts.map +1 -1
- package/server/dist/toolHelpers.js +67 -1
- package/server/dist/toolHelpers.js.map +1 -1
- package/server/dist/toolRuntime.d.ts +4 -0
- package/server/dist/toolRuntime.d.ts.map +1 -1
- package/server/dist/toolRuntime.js +12 -6
- package/server/dist/toolRuntime.js.map +1 -1
- package/server/dist/toolSchemas.d.ts +37 -1
- package/server/dist/toolSchemas.d.ts.map +1 -1
- package/server/dist/toolSchemas.js +33 -1
- package/server/dist/toolSchemas.js.map +1 -1
- package/server/dist/tools.d.ts +2 -2
- package/server/dist/tools.d.ts.map +1 -1
- package/server/dist/tools.js +65 -11
- package/server/dist/tools.js.map +1 -1
- package/server/dist/verdictExtract.d.ts.map +1 -1
- package/server/dist/verdictExtract.js +1 -0
- package/server/dist/verdictExtract.js.map +1 -1
- package/server/dist/workflowTools.d.ts +2 -2
- package/server/dist/workflowTools.d.ts.map +1 -1
- package/server/dist/workflowTools.js +16 -4
- package/server/dist/workflowTools.js.map +1 -1
- package/skills/browser-agent/SKILL.md +89 -0
package/extension/content.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
1
2
|
/**
|
|
2
|
-
* Browser
|
|
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.
|
|
8
|
+
if (globalThis.__BROWSER_AUTOMATION_CS_V5__) {
|
|
8
9
|
/* already armed */
|
|
9
10
|
} else {
|
|
10
|
-
globalThis.
|
|
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 =
|
|
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 =
|
|
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:
|
|
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
|
|
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
|
-
|
|
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
|
package/extension/manifest.json
CHANGED
|
@@ -1,23 +1,50 @@
|
|
|
1
|
-
{
|
|
2
|
-
"manifest_version": 3,
|
|
3
|
-
"name": "Browser
|
|
4
|
-
"version": "0.1
|
|
5
|
-
"description": "
|
|
6
|
-
"minimum_chrome_version": "114",
|
|
7
|
-
"action": {
|
|
8
|
-
"default_title": "Browser
|
|
9
|
-
"default_popup": "popup.html"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
},
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
+
}
|
package/extension/popup.html
CHANGED
|
@@ -1,56 +1,190 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8" />
|
|
5
|
-
<title>
|
|
6
|
-
<style>
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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> · 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>
|