@seekskyworld/open-browser 0.0.0-stage → 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/CONTRIBUTING.md +15 -0
- package/Docs/Agent/346/265/217/350/247/210/345/231/250/346/200/273/344/275/223/346/236/266/346/236/204.md +58 -0
- package/Docs/THIRD-PARTY-NOTICES.md +12 -0
- package/Docs/open-browser-api.d.ts +291 -0
- package/Docs/open-browser/344/273/273/345/212/241/350/257/204/346/265/213/346/214/207/345/215/227.md +59 -0
- package/Docs/open-browser/351/232/220/347/247/201/344/270/216/345/274/200/346/272/220/345/256/241/350/256/241.md +37 -0
- package/Docs//346/216/247/345/210/266/345/217/260/345/210/206/347/273/204/344/270/216/346/216/245/347/256/241/346/226/271/346/241/210.md +31 -0
- 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 +84 -0
- package/LICENSE +200 -0
- package/README.md +159 -2
- package/README.zh-CN.md +166 -0
- package/SECURITY.md +9 -0
- package/access-registry.mjs +156 -0
- package/action-execution.mjs +385 -0
- package/activity-notifier.mjs +34 -0
- package/api-contract.mjs +134 -0
- package/browser-extension/icons/open-browser-128.png +0 -0
- package/browser-extension/icons/open-browser-16.png +0 -0
- package/browser-extension/icons/open-browser-32.png +0 -0
- package/browser-extension/icons/open-browser-48.png +0 -0
- package/browser-extension/icons/open-browser-wordmark.png +0 -0
- package/browser-extension/manifest.json +35 -0
- package/browser-extension/newtab.css +26 -0
- package/browser-extension/newtab.html +19 -0
- package/browser-extension/newtab.js +174 -0
- package/browser-extension/phase-labels.js +9 -0
- package/browser-extension/popup.css +19 -0
- package/browser-extension/popup.html +56 -0
- package/browser-extension/popup.js +405 -0
- package/browser-extension/tab-action.js +138 -0
- package/browser-extension/worker.js +281 -0
- package/browser-extension/workspace-title.js +15 -0
- package/build-profile.mjs +23 -0
- package/capability-matrix.mjs +21 -0
- package/chromium-host.mjs +209 -0
- package/chromium-shell.mjs +179 -0
- package/cli.mjs +141 -0
- package/contract-validation.mjs +27 -0
- package/control.mjs +107 -0
- package/desktop/Info.plist +13 -0
- package/desktop/Launcher.m +117 -0
- package/desktop/OBControlBar.h +7 -0
- package/desktop/OBControlBar.m +217 -0
- package/desktop/OBPageView.h +6 -0
- package/desktop/OBPageView.m +348 -0
- package/desktop/WorkspacePanel.h +16 -0
- package/desktop/WorkspacePanel.m +916 -0
- package/desktop/archive-release.py +129 -0
- package/desktop/brand-keychain.py +111 -0
- package/desktop/brand-locales.py +93 -0
- package/desktop/brand-macos-icons.py +24 -0
- package/desktop/brand-windows-icons.mjs +48 -0
- package/desktop/build-macos.mjs +112 -0
- package/desktop/build-managed-input.mjs +37 -0
- package/desktop/build-portable.mjs +95 -0
- package/desktop/build-profile.mjs +6 -0
- package/desktop/build.mjs +13 -0
- package/desktop/create-shortcut.ps1 +9 -0
- package/desktop/generate-icons.py +39 -0
- package/desktop/icons/open-browser.icns +0 -0
- package/desktop/icons/open-browser.ico +0 -0
- package/desktop/install-menu-entry.mjs +24 -0
- package/desktop/macos-entitlements.plist +12 -0
- package/desktop/notarize-macos.mjs +145 -0
- package/desktop/package-assets.mjs +34 -0
- package/desktop/package-macos.mjs +54 -0
- package/desktop/patches/chromium-macos-keychain-service.patch +18 -0
- package/desktop/patches/chromium-managed-input.patch +144 -0
- package/desktop/portable-archive.py +22 -0
- package/desktop/sign.mjs +77 -0
- package/desktop/smoke-portable.mjs +65 -0
- package/desktop/start-profile.mjs +5 -0
- package/desktop/start.mjs +34 -0
- package/desktop/verify-macos-release.mjs +61 -0
- package/desktop/verify-upgrade.mjs +74 -0
- package/desktop/verify-version.mjs +12 -0
- package/desktop-page.mjs +211 -0
- package/diagnostics.mjs +37 -0
- package/downloads.mjs +110 -0
- package/engine-service.mjs +1158 -0
- package/hosted/README.md +74 -0
- package/hosted/cli.mjs +17 -0
- package/hosted/directory.mjs +261 -0
- package/hosted/init.mjs +37 -0
- package/hosted/server.mjs +129 -0
- package/managed-input.mjs +138 -0
- package/managed-popup.mjs +54 -0
- package/mcp-http.mjs +84 -0
- package/mcp-server.mjs +41 -0
- package/mcp.mjs +5 -0
- package/network-policy.mjs +107 -0
- package/output-store.mjs +96 -0
- package/package.json +77 -4
- package/page-activity.mjs +188 -0
- package/page-dialogs.mjs +53 -0
- package/page-observation.mjs +318 -0
- package/paths.mjs +22 -0
- package/privacy-config.mjs +95 -0
- package/receipt-store.mjs +198 -0
- package/runtime.mjs +53 -0
- package/scheduler.mjs +70 -0
- package/sdk.mjs +193 -0
- package/service.mjs +290 -0
- package/site-workflow.mjs +115 -0
- package/skill-links.mjs +90 -0
- package/skills/open-browser/SKILL.macos.md +112 -0
- package/skills/open-browser/SKILL.md +107 -0
- package/skills/open-browser/SKILL.windows.md +112 -0
- package/skills/open-browser/scripts/bootstrap.mjs +213 -0
- package/skills/open-browser/scripts/open-browser +21 -0
- package/skills/open-browser/scripts/open-browser.cmd +9 -0
- package/skills/open-browser/workflows/login-export.json +10 -0
- package/skills/open-browser/workflows/upload-verify.json +8 -0
- package/studio/demo-site.mjs +111 -0
- package/studio/demo.css +1 -0
- package/studio/index.html +66 -0
- package/studio/index.mjs +57 -0
- package/studio/native-demo.mjs +124 -0
- package/studio/studio.css +119 -0
- package/studio/studio.js +438 -0
- package/tab-adoption.mjs +77 -0
- package/uploads.mjs +63 -0
- package/visual-page.mjs +306 -0
- package/workspace-lifecycle.mjs +238 -0
- package/workspace-state.mjs +107 -0
package/page-dialogs.mjs
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {randomUUID} from 'node:crypto';
|
|
2
|
+
|
|
3
|
+
function fail(code) { throw Object.assign(new Error(code), {code}); }
|
|
4
|
+
|
|
5
|
+
export function attachDialogs(ws, tab, notify) {
|
|
6
|
+
function receive(dialog) {
|
|
7
|
+
const origin = URL.parse(tab.page.url())?.origin;
|
|
8
|
+
const op = [...ws.jobs].find(job => job.pageId === tab.id && job.dispatched);
|
|
9
|
+
// Playwright's Dialog identifies a page, but not the initiating frame.
|
|
10
|
+
// Only attribute a message to this origin if every frame shares it.
|
|
11
|
+
const singleOrigin = tab.page.frames().every(frame => URL.parse(frame.url())?.origin === origin);
|
|
12
|
+
if (!op || tab.dialog || ws.mode !== 'agent' || !ws.origins.has(origin) || !singleOrigin ||
|
|
13
|
+
!['alert','confirm','prompt'].includes(dialog.type())) {
|
|
14
|
+
void dialog.dismiss().catch(() => {});
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const type = dialog.type();
|
|
18
|
+
let message = dialog.message();
|
|
19
|
+
for (const secret of ws.credentials.values()) message = message.replaceAll(secret, '[redacted]');
|
|
20
|
+
const info = {dialogId:randomUUID(), pageId:tab.id, documentId:tab.documentId, origin,
|
|
21
|
+
operationId:op.receipt.operationId, type, message:message.slice(0,1024)};
|
|
22
|
+
tab.dialog = {dialog, info};
|
|
23
|
+
(op.receipt.dialogIds ??= []).push(info.dialogId);
|
|
24
|
+
notify();
|
|
25
|
+
}
|
|
26
|
+
tab.page.on('dialog',receive);
|
|
27
|
+
return () => {tab.page.off('dialog',receive); discardDialog(tab);};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function discardDialog(tab) {
|
|
31
|
+
const pending = tab.dialog;
|
|
32
|
+
tab.dialog = null;
|
|
33
|
+
if (pending) void pending.dialog.dismiss().catch(() => {});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function respondDialog(ws,tab,params,desktop) {
|
|
37
|
+
if (ws.generation !== params.controlGeneration) fail('stale_control');
|
|
38
|
+
if (desktop ? !['human','transferring'].includes(ws.mode) : ws.mode !== 'agent')
|
|
39
|
+
fail(desktop ? 'take_control_first' : 'workspace_under_user_control');
|
|
40
|
+
const pending = tab.dialog;
|
|
41
|
+
if (!pending || pending.info.dialogId !== params.dialogId) fail('dialog_not_found');
|
|
42
|
+
if (pending.info.documentId !== tab.documentId || !ws.origins.has(pending.info.origin) ||
|
|
43
|
+
pending.info.origin !== URL.parse(tab.page.url())?.origin) fail('stale_document');
|
|
44
|
+
if (typeof params.accept !== 'boolean' || (params.text !== undefined &&
|
|
45
|
+
(!params.accept || pending.info.type !== 'prompt' || typeof params.text !== 'string' || params.text.length > 2048)))
|
|
46
|
+
fail('invalid_params');
|
|
47
|
+
tab.dialog = null; // Claim before the first await so concurrent replies cannot both reach the site.
|
|
48
|
+
try {
|
|
49
|
+
if (params.accept) await pending.dialog.accept(params.text);
|
|
50
|
+
else await pending.dialog.dismiss();
|
|
51
|
+
} catch { fail('inspect_before_retry'); }
|
|
52
|
+
return {dialogId:params.dialogId, accepted:params.accept};
|
|
53
|
+
}
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
export function inspectDocument(options = {}) {
|
|
2
|
+
const textOnly = options === true || options.textOnly;
|
|
3
|
+
if (options.origins && (!options.origins.includes(self.origin) || !options.origins.includes(location.origin))) return null;
|
|
4
|
+
const excluded = '[aria-hidden="true" i],[inert],[data-open-browser-private]';
|
|
5
|
+
// closest() stops at a shadow boundary. Walk the composed ancestry so a
|
|
6
|
+
// private or inert host also protects its projected and shadow children.
|
|
7
|
+
function composedMatch(el, selector) {
|
|
8
|
+
for(let node=el;node;node=node.assignedSlot || node.parentElement || node.getRootNode().host)
|
|
9
|
+
if(node.matches(selector)) return true;
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
const visible = node => node.checkVisibility({visibilityProperty:true,opacityProperty:true}) &&
|
|
13
|
+
node.getClientRects().length>0 && !composedMatch(node,excluded);
|
|
14
|
+
const disabled = node => node.matches(':disabled') || composedMatch(node,'[aria-disabled="true" i]');
|
|
15
|
+
const region = options.region;
|
|
16
|
+
function intersects(el) {
|
|
17
|
+
if(!region) return true;
|
|
18
|
+
const r=el.getBoundingClientRect();
|
|
19
|
+
return r.right>region.x && r.left<region.x+region.width && r.bottom>region.y && r.top<region.y+region.height;
|
|
20
|
+
}
|
|
21
|
+
function* walk(root,mask) {
|
|
22
|
+
const stack=[document.createTreeWalker(root,mask | NodeFilter.SHOW_ELEMENT)];
|
|
23
|
+
while(stack.length) {
|
|
24
|
+
const node=stack.at(-1).nextNode();
|
|
25
|
+
if(!node) {stack.pop();continue;}
|
|
26
|
+
if(node.shadowRoot) stack.push(document.createTreeWalker(node.shadowRoot,mask | NodeFilter.SHOW_ELEMENT));
|
|
27
|
+
yield node;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function textWindow(root,limit,offset=0,scoped=false) {
|
|
31
|
+
let content='',position=0;
|
|
32
|
+
const protectedText='script,style,noscript,input,textarea,select,[contenteditable]';
|
|
33
|
+
for(const node of walk(root,NodeFilter.SHOW_TEXT)) {
|
|
34
|
+
if(node.nodeType!==Node.TEXT_NODE) continue;
|
|
35
|
+
const el=node.parentElement || node.getRootNode().host;
|
|
36
|
+
if(!el || !visible(el) || composedMatch(el,protectedText) || (scoped && !intersects(el))) continue;
|
|
37
|
+
const value=node.textContent.trim();
|
|
38
|
+
if(!value) continue;
|
|
39
|
+
const piece=(position?' ':'')+value;
|
|
40
|
+
const start=Math.max(0,offset-position);
|
|
41
|
+
position+=piece.length;
|
|
42
|
+
if(start<piece.length) content+=piece.slice(start,start+limit+1-content.length);
|
|
43
|
+
if(content.length>limit) break;
|
|
44
|
+
}
|
|
45
|
+
return {text:content.slice(0,limit),more:content.length>limit};
|
|
46
|
+
}
|
|
47
|
+
const visibleText=(root,limit)=>textWindow(root,limit).text;
|
|
48
|
+
// Native top-layer dialogs follow paint order, which can differ from DOM order.
|
|
49
|
+
const modalSelector='dialog:modal,[role="dialog"][aria-modal="true"],[role="alertdialog"][aria-modal="true"]';
|
|
50
|
+
const dialogs=[...document.querySelectorAll(modalSelector)];
|
|
51
|
+
for(let focused=document.activeElement;focused?.shadowRoot?.activeElement;) {
|
|
52
|
+
const root=focused.shadowRoot;
|
|
53
|
+
dialogs.push(...root.querySelectorAll(modalSelector));
|
|
54
|
+
focused=root.activeElement;
|
|
55
|
+
}
|
|
56
|
+
const painted=dialogs.filter(el=>el.checkVisibility({visibilityProperty:true,opacityProperty:true}) && el.getClientRects().length);
|
|
57
|
+
const front=painted.findLast(el=>{
|
|
58
|
+
const r=el.getBoundingClientRect();
|
|
59
|
+
const hit=el.getRootNode().elementFromPoint(r.x+r.width/2,r.y+r.height/2);
|
|
60
|
+
return hit && (el===hit || el.contains(hit));
|
|
61
|
+
}) ?? painted.at(-1);
|
|
62
|
+
if(options.foregroundTarget) {
|
|
63
|
+
if(!front) return true;
|
|
64
|
+
for(let node=options.foregroundTarget;node;node=node.assignedSlot || node.parentElement || node.getRootNode().host)
|
|
65
|
+
if(node===front) return true;
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
let foreground;
|
|
69
|
+
if(front && visible(front)) {
|
|
70
|
+
const label=(front.getAttribute('aria-labelledby') || '').split(/\s+/)
|
|
71
|
+
.map(id=>front.getRootNode().getElementById(id)).filter(el=>el && visible(el))
|
|
72
|
+
.map(el=>visibleText(el,160)).join(' ');
|
|
73
|
+
const {x,y,width,height}=front.getBoundingClientRect();
|
|
74
|
+
foreground={role:front.getAttribute('role') || 'dialog',name:(label || front.getAttribute('aria-label') || '').slice(0,160),
|
|
75
|
+
bounds:{x,y,width,height}};
|
|
76
|
+
}
|
|
77
|
+
if (options.canvas) {
|
|
78
|
+
const root = front || document;
|
|
79
|
+
let truncated = false;
|
|
80
|
+
const rows = (selector, describe) => {
|
|
81
|
+
const result = [];
|
|
82
|
+
for (const el of root.querySelectorAll(selector)) {
|
|
83
|
+
if (!visible(el) || composedMatch(el, 'input,textarea,select,[contenteditable]')) continue;
|
|
84
|
+
if (result.length >= 100) { truncated = true; break; }
|
|
85
|
+
result.push(describe(el));
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
};
|
|
89
|
+
const label = el => visibleText(el, 512) || (el.getAttribute('aria-label') || '').slice(0, 512);
|
|
90
|
+
const nodeRows = rows('.react-flow__node', el => ({
|
|
91
|
+
id:(el.getAttribute('data-id') || '').slice(0,128), label:label(el), selected:el.classList.contains('selected')
|
|
92
|
+
}));
|
|
93
|
+
const edges = rows('.react-flow__edge', el => {
|
|
94
|
+
const accessibleLabel = (el.getAttribute('aria-label') || '').slice(0,512);
|
|
95
|
+
const endpoints = /^Edge from (\S+) to (\S+)$/.exec(accessibleLabel);
|
|
96
|
+
return {id:(el.getAttribute('data-id') || '').slice(0,128), label:accessibleLabel || label(el),
|
|
97
|
+
selected:el.classList.contains('selected'), ...(endpoints && {source:endpoints[1],target:endpoints[2]})};
|
|
98
|
+
});
|
|
99
|
+
const messages = rows('[data-message-author-role], [role="log"] > [role="article"]', el => ({
|
|
100
|
+
role:['user','assistant','system','tool'].includes(el.dataset.messageAuthorRole) ? el.dataset.messageAuthorRole : 'message',
|
|
101
|
+
text:label(el)
|
|
102
|
+
}));
|
|
103
|
+
const attachments = rows('a[download]', el => ({label:label(el)}));
|
|
104
|
+
return {adapter:root.querySelector('.react-flow') ? 'react-flow' : messages.length ? 'chat' : 'unsupported',
|
|
105
|
+
nodes:nodeRows, edges, messages, attachments, truncated};
|
|
106
|
+
}
|
|
107
|
+
const nodes=[],details=[];
|
|
108
|
+
function stateOf(el) {
|
|
109
|
+
const state = {};
|
|
110
|
+
for (const key of ['checked', 'pressed', 'expanded', 'selected']) {
|
|
111
|
+
const raw = el.getAttribute('aria-' + key);
|
|
112
|
+
if (raw === 'true' || raw === 'false') state[key] = raw === 'true';
|
|
113
|
+
else if (raw === 'mixed' && (key === 'checked' || key === 'pressed')) state[key] = raw;
|
|
114
|
+
}
|
|
115
|
+
if (el.matches('input[type="checkbox"],input[type="radio"]'))
|
|
116
|
+
state.checked = el.indeterminate && el.type === 'checkbox' ? 'mixed' : el.checked;
|
|
117
|
+
return state;
|
|
118
|
+
}
|
|
119
|
+
const selector='[role="checkbox"],[role="radio"],[role="switch"],[role="tab"],[role="option"],a[href],button,input,textarea,select,label,[role="button"],[role="link"],[contenteditable="true"]';
|
|
120
|
+
const offset=options.elementOffset===undefined?0:options.elementOffset;
|
|
121
|
+
const limit=options.limit??180;
|
|
122
|
+
let seen=0,moreControls=false;
|
|
123
|
+
const locator=options.locator;
|
|
124
|
+
const candidates=[];
|
|
125
|
+
let matchCount=0;
|
|
126
|
+
function semanticScope(el, wanted) {
|
|
127
|
+
for(let parent=el.parentElement || el.getRootNode().host; parent;
|
|
128
|
+
parent=parent.assignedSlot || parent.parentElement || parent.getRootNode().host) {
|
|
129
|
+
const role=parent.getAttribute('role') || {section:'region',tr:'row',fieldset:'group',form:'form',dialog:'dialog'}[parent.localName];
|
|
130
|
+
if(!['region','row','group','form','dialog','listitem','article'].includes(role)) continue;
|
|
131
|
+
const labelled=(parent.getAttribute('aria-labelledby') || '').split(/\s+/).filter(Boolean)
|
|
132
|
+
.map(id=>parent.getRootNode().getElementById(id)).filter(node=>node && visible(node))
|
|
133
|
+
.map(node=>visibleText(node,160)).join(' ');
|
|
134
|
+
const name=(labelled || parent.getAttribute('aria-label') || visibleText(parent,160)).slice(0,160);
|
|
135
|
+
if(!wanted || (role===wanted.role && name===wanted.name)) return {role,name};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function add(el,detail) {
|
|
139
|
+
if(locator) {
|
|
140
|
+
if(detail.role!==locator.role || detail.name!==locator.name) return;
|
|
141
|
+
const within=semanticScope(el,locator.within);
|
|
142
|
+
if(locator.within && !within) return;
|
|
143
|
+
matchCount++;
|
|
144
|
+
if(candidates.length<8) candidates.push({role:detail.role,name:detail.name,...(within && {within})});
|
|
145
|
+
if(matchCount===1) {nodes.push(el);details.push(detail);}
|
|
146
|
+
if(matchCount===2) {nodes.length=0;details.length=0;}
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
if(options.name && !detail.name.toLowerCase().includes(options.name.toLowerCase())) return;
|
|
150
|
+
if(seen++<offset) return;
|
|
151
|
+
if(nodes.length===limit) {moreControls=true;return;}
|
|
152
|
+
nodes.push(el);details.push(detail);
|
|
153
|
+
}
|
|
154
|
+
for(const el of textOnly || offset===null ? [] : walk(front || document,NodeFilter.SHOW_ELEMENT)) {
|
|
155
|
+
if(moreControls) break;
|
|
156
|
+
if(!el.matches(selector) || !intersects(el)) continue;
|
|
157
|
+
if (!visible(el) || disabled(el) || el.matches('input[type="hidden"]')) continue;
|
|
158
|
+
if (el instanceof HTMLLabelElement && !el.matches('[role="button"],[role="link"],[contenteditable="true"]')) {
|
|
159
|
+
// Chromium dispatches the native activation through the visible label.
|
|
160
|
+
// Keep the ref on the control when the control already has a target.
|
|
161
|
+
const control = el.control;
|
|
162
|
+
if (!control || composedMatch(control,excluded) || disabled(control) || visible(control) ||
|
|
163
|
+
!control.matches('input[type="checkbox"],input[type="radio"]')) continue;
|
|
164
|
+
const name = visibleText(el, 160);
|
|
165
|
+
if (name) add(el,{role:'label',name,...stateOf(control)});
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
const type = el.type || '';
|
|
169
|
+
let role = el.getAttribute('role') || 'textbox';
|
|
170
|
+
if (el.matches('a,[role="link"]')) role = 'link';
|
|
171
|
+
else if (el.matches('button,[role="button"],input[type="submit"],input[type="button"]')) role = 'button';
|
|
172
|
+
else if (el.matches('select')) role = 'combobox';
|
|
173
|
+
else if (['checkbox', 'radio'].includes(type)) role = type;
|
|
174
|
+
const labels = Array.from(el.labels || []).filter(visible).map(label => visibleText(label, 160)).join(' ');
|
|
175
|
+
const caption = ['button', 'link'].includes(role) ? visibleText(el, 160) : '';
|
|
176
|
+
const submitText = el.matches('input[type="submit"],input[type="button"]') ? el.value : '';
|
|
177
|
+
let referenced = '';
|
|
178
|
+
for (const id of (el.getAttribute('aria-labelledby') || '').match(/\S+/g) || []) {
|
|
179
|
+
const label = el.getRootNode().getElementById(id);
|
|
180
|
+
if (!label || !visible(label)) continue;
|
|
181
|
+
const part = visibleText(label, 160 - referenced.length);
|
|
182
|
+
if (part) referenced += (referenced ? ' ' : '') + part;
|
|
183
|
+
if (referenced.length >= 160) break;
|
|
184
|
+
}
|
|
185
|
+
const name = referenced || el.getAttribute('aria-label') || labels || caption || submitText
|
|
186
|
+
|| el.getAttribute('placeholder') || el.getAttribute('name') || role;
|
|
187
|
+
const choices = role === 'combobox' ? Array.from(el.options).slice(0, 64)
|
|
188
|
+
.map(option => ({ label: option.label.slice(0, 160), value: option.value.slice(0, 256) })) : undefined;
|
|
189
|
+
add(el,{ role, name: name.trim().slice(0,160), ...stateOf(el), ...(choices && {options:choices}) });
|
|
190
|
+
}
|
|
191
|
+
const textOffset=options.textOffset===undefined?0:options.textOffset;
|
|
192
|
+
const textLimit=options.textLimit??8000,padding=options.padding??0;
|
|
193
|
+
const start=Math.max(0,(textOffset??0)-padding);
|
|
194
|
+
const skip=(textOffset??0)-start;
|
|
195
|
+
const window=locator || options.name || textOffset===null ? {text:'',more:false} :
|
|
196
|
+
textWindow(front || document.body || document.documentElement,textLimit+skip+padding,start,true);
|
|
197
|
+
const text=window.text.slice(skip,skip+textLimit);
|
|
198
|
+
const more=window.more || window.text.length>skip+textLimit;
|
|
199
|
+
const textWindowInfo=padding ? {padded:window.text,skip,length:text.length} : undefined;
|
|
200
|
+
if (options.origins && textOnly) return {origin:self.origin,text,textWindowInfo};
|
|
201
|
+
if (textOnly) return text;
|
|
202
|
+
const next=moreControls || more ? {elementOffset:moreControls?offset+nodes.length:null,textOffset:more?textOffset+text.length:null} : null;
|
|
203
|
+
if (options.expectedNode) return nodes.length===1 && nodes[0]===options.expectedNode;
|
|
204
|
+
const match=locator ? {status:matchCount===1?'unique':matchCount?'ambiguous':'missing',count:matchCount,candidates} : undefined;
|
|
205
|
+
const summary={text,details,next,origin:self.origin,textWindowInfo,foreground,...(match && {match})};
|
|
206
|
+
if (options.summaryOnly) return summary;
|
|
207
|
+
if (!options.previousNodes) return {nodes,summary};
|
|
208
|
+
// Match the DOM objects themselves. Reordering or duplicate labels cannot
|
|
209
|
+
// redirect an old ref to a replacement element.
|
|
210
|
+
const previous = new Map(options.previousNodes.map((node, index) => [node, index]));
|
|
211
|
+
const freshNodes = {};
|
|
212
|
+
const previousIndices = nodes.map((node, index) => {
|
|
213
|
+
if (previous.has(node)) return previous.get(node);
|
|
214
|
+
freshNodes[index] = node;
|
|
215
|
+
return -1;
|
|
216
|
+
});
|
|
217
|
+
return { nodes, freshNodes, summary:{...summary,previousIndices} };
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Only delegated readers use this path. Owners retain Playwright element handles for actions.
|
|
221
|
+
export async function readDocumentSummary(tab, origins, options = {}) {
|
|
222
|
+
if (!tab.summarySession) tab.summarySession = await tab.page.context().newCDPSession(tab.page);
|
|
223
|
+
const session = tab.summarySession;
|
|
224
|
+
const allowed = JSON.stringify(origins);
|
|
225
|
+
const expression = `(${allowed}.includes(self.origin) && ${allowed}.includes(location.origin)) ? (${inspectDocument})(${JSON.stringify(options)}).summary : null`;
|
|
226
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
227
|
+
if (!tab.summaryContext || tab.summaryContext.documentId !== tab.documentId) {
|
|
228
|
+
const documentId = tab.documentId;
|
|
229
|
+
const {frameTree} = await session.send('Page.getFrameTree');
|
|
230
|
+
const {executionContextId} = await session.send('Page.createIsolatedWorld', {
|
|
231
|
+
frameId: frameTree.frame.id, worldName: 'open-browser-observer',
|
|
232
|
+
});
|
|
233
|
+
tab.summaryContext = { documentId, executionContextId };
|
|
234
|
+
}
|
|
235
|
+
let response;
|
|
236
|
+
try {
|
|
237
|
+
response = await session.send('Runtime.evaluate', {
|
|
238
|
+
contextId: tab.summaryContext.executionContextId, expression, returnByValue: true,
|
|
239
|
+
});
|
|
240
|
+
} catch (error) {
|
|
241
|
+
// A renderer may invalidate the world before its navigation event reaches the service.
|
|
242
|
+
if (attempt || !/context/i.test(error.message)) throw error;
|
|
243
|
+
tab.summaryContext = undefined;
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
if (response.exceptionDetails) throw new Error('observation_failed');
|
|
247
|
+
if (!response.result.value) throw Object.assign(new Error('origin_denied'), {code:'origin_denied'});
|
|
248
|
+
return response.result.value;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export async function frameAllowed(frame,origins) {
|
|
253
|
+
for(let child=frame; child.parentFrame(); child=child.parentFrame()) {
|
|
254
|
+
const url=URL.parse(child.url());
|
|
255
|
+
if(child.isDetached() || !url || !['http:','https:'].includes(url.protocol) ||
|
|
256
|
+
url.username || url.password || !origins.has(url.origin)) return false;
|
|
257
|
+
const owner=await child.frameElement();
|
|
258
|
+
try {
|
|
259
|
+
if(!await child.parentFrame().evaluate(inspectDocument,{foregroundTarget:owner})) return false;
|
|
260
|
+
const sandbox=await owner.getAttribute('sandbox');
|
|
261
|
+
if(sandbox!==null && !sandbox.split(/\s+/).includes('allow-same-origin')) return false;
|
|
262
|
+
if(!await owner.evaluate(node=>{
|
|
263
|
+
if(!node.checkVisibility({visibilityProperty:true,opacityProperty:true}) || !node.getClientRects().length) return false;
|
|
264
|
+
for(let el=node;el;el=el.assignedSlot || el.parentElement || el.getRootNode().host)
|
|
265
|
+
if(el.matches('[inert],[aria-hidden="true" i],[data-open-browser-private]')) return false;
|
|
266
|
+
return true;
|
|
267
|
+
})) return false;
|
|
268
|
+
} finally { await owner.dispose().catch(()=>{}); }
|
|
269
|
+
}
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export async function observeFrames(page, origins, redact, padding=0) {
|
|
274
|
+
const frames = [];
|
|
275
|
+
let remaining = 8000;
|
|
276
|
+
// Direct visible child frames only. A blank or opaque sandbox has no
|
|
277
|
+
// explicit HTTP(S) origin. No cross-frame action handles leave this helper.
|
|
278
|
+
const candidates = page.mainFrame().childFrames().slice(0, 16)
|
|
279
|
+
.filter(frame => origins.has(URL.parse(frame.url())?.origin));
|
|
280
|
+
const allowed = (await Promise.all(candidates.map(async frame => {
|
|
281
|
+
try { return await frameAllowed(frame, origins) ? frame : null; }
|
|
282
|
+
catch (error) {
|
|
283
|
+
if (!frame.isDetached() && !/context was destroyed|navigat/i.test(error.message)) throw error;
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
}))).filter(Boolean);
|
|
287
|
+
for (const frame of allowed) {
|
|
288
|
+
if (!remaining) break;
|
|
289
|
+
try {
|
|
290
|
+
const data=await frame.evaluate(inspectDocument,{textOnly:true,origins:[...origins],textLimit:remaining,padding});
|
|
291
|
+
if (data && origins.has(data.origin) && URL.parse(frame.url())?.origin === data.origin) {
|
|
292
|
+
const text = redact(data.text,data.textWindowInfo);
|
|
293
|
+
frames.push({ origin: data.origin, text });
|
|
294
|
+
remaining -= data.text.length;
|
|
295
|
+
}
|
|
296
|
+
} catch (error) {
|
|
297
|
+
if (!frame.isDetached() && !/context was destroyed|navigat/i.test(error.message)) throw error;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return frames;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export function observationDelta(before, after) {
|
|
304
|
+
const removed = before.elements.map(({role, name}) => ({role, name}));
|
|
305
|
+
const added = [];
|
|
306
|
+
for (const {role, name} of after.elements) {
|
|
307
|
+
const index = removed.findIndex(item => item.role === role && item.name === name);
|
|
308
|
+
if (index < 0) added.push({role, name});
|
|
309
|
+
else removed.splice(index, 1);
|
|
310
|
+
}
|
|
311
|
+
const textChanged = before.text !== after.text;
|
|
312
|
+
const oldByRef = new Map(before.elements.map(item => [item.ref, item]));
|
|
313
|
+
const changed = after.elements.filter(item => {
|
|
314
|
+
const old = oldByRef.get(item.ref);
|
|
315
|
+
return old && ['checked','pressed','expanded','selected'].some(key => item[key] !== old[key]);
|
|
316
|
+
});
|
|
317
|
+
return { ...(changed.length && {changed}), textChanged, ...(textChanged && { text: after.text }), added, removed };
|
|
318
|
+
}
|
package/paths.mjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { buildProfile, scopedBuildRoot } from './build-profile.mjs';
|
|
5
|
+
|
|
6
|
+
export const profileId = process.env.OPEN_BROWSER_PROFILE || 'default';
|
|
7
|
+
const base = scopedBuildRoot(path.resolve(process.env.OPEN_BROWSER_STATE_DIR || path.join(homedir(), '.open-browser')));
|
|
8
|
+
|
|
9
|
+
export function pathsForProfile(id) {
|
|
10
|
+
if (typeof id !== 'string' || !/^[a-z0-9][a-z0-9_-]{0,47}$/.test(id)) throw new Error('invalid_profile');
|
|
11
|
+
const stateDir = id === 'default' ? base : path.join(base, 'profiles', id);
|
|
12
|
+
const instance = createHash('sha256').update(stateDir).digest('hex').slice(0, 16);
|
|
13
|
+
const socketFile = path.join(stateDir, 'open-browser.sock');
|
|
14
|
+
const socketPath = process.platform === 'win32'
|
|
15
|
+
? '\\\\.\\pipe\\open-browser-' + instance
|
|
16
|
+
: Buffer.byteLength(socketFile) < 100 ? socketFile : path.join('/tmp', 'open-browser-' + process.getuid() + '-' + instance + '.sock');
|
|
17
|
+
return {stateDir, socketPath, tokenPath:path.join(stateDir, 'open-browser.token'), pidPath:path.join(stateDir, 'open-browser.pid')};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { buildProfile };
|
|
21
|
+
export const {stateDir, socketPath, tokenPath, pidPath} = pathsForProfile(profileId);
|
|
22
|
+
export const adminTokenPath = path.join(stateDir, 'open-browser-admin.token');
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// Privacy defaults are deliberately local-first. Page traffic is still
|
|
2
|
+
// governed by network-policy.mjs and the user's explicit target origins.
|
|
3
|
+
const serviceFeatures = [
|
|
4
|
+
'AutofillServerCommunication',
|
|
5
|
+
'OptimizationHints',
|
|
6
|
+
'MediaRouter',
|
|
7
|
+
'Translate',
|
|
8
|
+
'CertificateTransparencyComponentUpdater',
|
|
9
|
+
'InterestFeedContentSuggestions',
|
|
10
|
+
'Reporting',
|
|
11
|
+
'NetworkTimeServiceQuery',
|
|
12
|
+
'Topics',
|
|
13
|
+
'Fledge',
|
|
14
|
+
'NewTabPage',
|
|
15
|
+
'Signin',
|
|
16
|
+
'AccountConsistency',
|
|
17
|
+
].join(',');
|
|
18
|
+
|
|
19
|
+
const strictArgs = Object.freeze([
|
|
20
|
+
'--disable-background-networking',
|
|
21
|
+
'--disable-component-update',
|
|
22
|
+
'--disable-domain-reliability',
|
|
23
|
+
'--disable-default-apps',
|
|
24
|
+
'--disable-breakpad',
|
|
25
|
+
'--disable-crash-reporter',
|
|
26
|
+
'--disable-sync',
|
|
27
|
+
'--disable-account-consistency',
|
|
28
|
+
'--disable-signin-promo',
|
|
29
|
+
'--disable-search-engine-choice-screen',
|
|
30
|
+
'--disable-network-time',
|
|
31
|
+
'--disable-variations',
|
|
32
|
+
'--no-first-run',
|
|
33
|
+
'--no-default-browser-check',
|
|
34
|
+
'--no-pings',
|
|
35
|
+
`--disable-features=${serviceFeatures}`,
|
|
36
|
+
]);
|
|
37
|
+
|
|
38
|
+
export function privacyProfile() {
|
|
39
|
+
return process.env.OPEN_BROWSER_PRIVACY_PROFILE?.trim().toLowerCase() || 'strict';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function chromiumPrivacyArgs() {
|
|
43
|
+
// A deliberate opt-in exists for compatibility testing with Chromium
|
|
44
|
+
// services. The shipped default remains strict and has no telemetry path.
|
|
45
|
+
return privacyProfile() === 'compatibility' ? [] : [...strictArgs];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function privacyCapabilities() {
|
|
49
|
+
const profile = privacyProfile();
|
|
50
|
+
return {
|
|
51
|
+
profile,
|
|
52
|
+
telemetry: 'disabled',
|
|
53
|
+
chromiumServices: profile === 'compatibility' ? 'compatibility' : 'reduced',
|
|
54
|
+
taskNetwork: 'explicit-origins',
|
|
55
|
+
diagnostics: 'redacted',
|
|
56
|
+
credentials: 'memory-scoped',
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const secretKey = '(?:password|passwd|passcode|token|secret|api[_-]?key|access[_-]?token|refresh[_-]?token|authorization|auth|session(?:id)?|sid|cookie|csrf|xsrf|otp|pin|code|signature|credential|private[_-]?key)';
|
|
61
|
+
const keyValue = new RegExp(`(\\b${secretKey}\\b\\s*(?:=|:|->)\\s*)([^\\s,;&]+)`, 'giu');
|
|
62
|
+
const bearer = /\b(?:Bearer|Basic)\s+[A-Za-z0-9._~+\/-]{8,}\b/giu;
|
|
63
|
+
const jwt = /\beyJ[A-Za-z0-9_-]{6,}\.[A-Za-z0-9_-]{6,}\.[A-Za-z0-9_-]{6,}\b/gu;
|
|
64
|
+
|
|
65
|
+
function redactUrl(value) {
|
|
66
|
+
let url;
|
|
67
|
+
try { url = new URL(value); } catch { return value; }
|
|
68
|
+
if (!['http:', 'https:'].includes(url.protocol)) return value;
|
|
69
|
+
for (const key of url.searchParams.keys()) {
|
|
70
|
+
if (new RegExp(`^${secretKey}$`, 'iu').test(key)) url.searchParams.set(key, '[redacted]');
|
|
71
|
+
}
|
|
72
|
+
// Fragments are client-side state and frequently contain OAuth tokens.
|
|
73
|
+
url.hash = '';
|
|
74
|
+
return url.href;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function redactSensitiveText(value, knownSecrets = []) {
|
|
78
|
+
if (typeof value !== 'string' || !value) return value;
|
|
79
|
+
let text = value;
|
|
80
|
+
for (const secret of knownSecrets) {
|
|
81
|
+
if (typeof secret === 'string' && secret.length) text = text.replaceAll(secret, '[redacted]');
|
|
82
|
+
}
|
|
83
|
+
text = text.replace(/https?:\/\/[^\s<>"']+/giu, redactUrl);
|
|
84
|
+
text = text.replace(keyValue, '$1[redacted]');
|
|
85
|
+
text = text.replace(bearer, '[redacted authorization]');
|
|
86
|
+
text = text.replace(jwt, '[redacted token]');
|
|
87
|
+
return text;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export const privacyDocumentation = Object.freeze({
|
|
91
|
+
defaultProfile: 'strict',
|
|
92
|
+
optInProfile: 'compatibility',
|
|
93
|
+
optInVariable: 'OPEN_BROWSER_PRIVACY_PROFILE=compatibility',
|
|
94
|
+
outbound: 'Chromium background services are reduced by default. Task navigation still requires explicit origins.',
|
|
95
|
+
});
|