@developerz.ai/ui-debugger-mcp 1.0.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 +21 -0
- package/README.md +295 -0
- package/dist/adapters/android/adb.d.ts +38 -0
- package/dist/adapters/android/adb.js +72 -0
- package/dist/adapters/android/adb.js.map +1 -0
- package/dist/adapters/android/android-adapter.d.ts +63 -0
- package/dist/adapters/android/android-adapter.js +306 -0
- package/dist/adapters/android/android-adapter.js.map +1 -0
- package/dist/adapters/android/commands.d.ts +59 -0
- package/dist/adapters/android/commands.js +178 -0
- package/dist/adapters/android/commands.js.map +1 -0
- package/dist/adapters/android/uiautomator.d.ts +81 -0
- package/dist/adapters/android/uiautomator.js +296 -0
- package/dist/adapters/android/uiautomator.js.map +1 -0
- package/dist/adapters/browser/browser-adapter.d.ts +72 -0
- package/dist/adapters/browser/browser-adapter.js +434 -0
- package/dist/adapters/browser/browser-adapter.js.map +1 -0
- package/dist/adapters/browser/cdp.d.ts +83 -0
- package/dist/adapters/browser/cdp.js +308 -0
- package/dist/adapters/browser/cdp.js.map +1 -0
- package/dist/adapters/browser/query.d.ts +25 -0
- package/dist/adapters/browser/query.js +85 -0
- package/dist/adapters/browser/query.js.map +1 -0
- package/dist/adapters/contract.d.ts +159 -0
- package/dist/adapters/contract.js +22 -0
- package/dist/adapters/contract.js.map +1 -0
- package/dist/adapters/desktop/atspi.d.ts +95 -0
- package/dist/adapters/desktop/atspi.js +359 -0
- package/dist/adapters/desktop/atspi.js.map +1 -0
- package/dist/adapters/desktop/capture.d.ts +35 -0
- package/dist/adapters/desktop/capture.js +67 -0
- package/dist/adapters/desktop/capture.js.map +1 -0
- package/dist/adapters/desktop/desktop-adapter.d.ts +60 -0
- package/dist/adapters/desktop/desktop-adapter.js +215 -0
- package/dist/adapters/desktop/desktop-adapter.js.map +1 -0
- package/dist/adapters/desktop/input.d.ts +67 -0
- package/dist/adapters/desktop/input.js +191 -0
- package/dist/adapters/desktop/input.js.map +1 -0
- package/dist/adapters/desktop/proc.d.ts +23 -0
- package/dist/adapters/desktop/proc.js +38 -0
- package/dist/adapters/desktop/proc.js.map +1 -0
- package/dist/adapters/factory.d.ts +23 -0
- package/dist/adapters/factory.js +45 -0
- package/dist/adapters/factory.js.map +1 -0
- package/dist/agent/belt/act.d.ts +100 -0
- package/dist/agent/belt/act.js +166 -0
- package/dist/agent/belt/act.js.map +1 -0
- package/dist/agent/belt/look.d.ts +98 -0
- package/dist/agent/belt/look.js +160 -0
- package/dist/agent/belt/look.js.map +1 -0
- package/dist/agent/belt/observe.d.ts +102 -0
- package/dist/agent/belt/observe.js +185 -0
- package/dist/agent/belt/observe.js.map +1 -0
- package/dist/agent/belt/report.d.ts +133 -0
- package/dist/agent/belt/report.js +112 -0
- package/dist/agent/belt/report.js.map +1 -0
- package/dist/agent/loop.d.ts +136 -0
- package/dist/agent/loop.js +173 -0
- package/dist/agent/loop.js.map +1 -0
- package/dist/agent/models.d.ts +26 -0
- package/dist/agent/models.js +22 -0
- package/dist/agent/models.js.map +1 -0
- package/dist/agent/prompts/android-addendum.d.ts +12 -0
- package/dist/agent/prompts/android-addendum.js +76 -0
- package/dist/agent/prompts/android-addendum.js.map +1 -0
- package/dist/agent/prompts/compose.d.ts +30 -0
- package/dist/agent/prompts/compose.js +52 -0
- package/dist/agent/prompts/compose.js.map +1 -0
- package/dist/agent/prompts/debug-agent.d.ts +9 -0
- package/dist/agent/prompts/debug-agent.js +102 -0
- package/dist/agent/prompts/debug-agent.js.map +1 -0
- package/dist/agent/prompts/desktop-addendum.d.ts +10 -0
- package/dist/agent/prompts/desktop-addendum.js +66 -0
- package/dist/agent/prompts/desktop-addendum.js.map +1 -0
- package/dist/agent/prompts/web-addendum.d.ts +9 -0
- package/dist/agent/prompts/web-addendum.js +70 -0
- package/dist/agent/prompts/web-addendum.js.map +1 -0
- package/dist/agent/provider.d.ts +17 -0
- package/dist/agent/provider.js +29 -0
- package/dist/agent/provider.js.map +1 -0
- package/dist/cli/control.d.ts +19 -0
- package/dist/cli/control.js +152 -0
- package/dist/cli/control.js.map +1 -0
- package/dist/cli/help.d.ts +9 -0
- package/dist/cli/help.js +41 -0
- package/dist/cli/help.js.map +1 -0
- package/dist/cli/init.d.ts +20 -0
- package/dist/cli/init.js +119 -0
- package/dist/cli/init.js.map +1 -0
- package/dist/config/load.d.ts +64 -0
- package/dist/config/load.js +105 -0
- package/dist/config/load.js.map +1 -0
- package/dist/config/schema.d.ts +105 -0
- package/dist/config/schema.js +62 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/errors.d.ts +41 -0
- package/dist/errors.js +90 -0
- package/dist/errors.js.map +1 -0
- package/dist/findings/schema.d.ts +64 -0
- package/dist/findings/schema.js +27 -0
- package/dist/findings/schema.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +95 -0
- package/dist/main.js.map +1 -0
- package/dist/mcp/server.d.ts +25 -0
- package/dist/mcp/server.js +31 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/tools/describe.d.ts +12 -0
- package/dist/mcp/tools/describe.js +32 -0
- package/dist/mcp/tools/describe.js.map +1 -0
- package/dist/mcp/tools/end-session.d.ts +11 -0
- package/dist/mcp/tools/end-session.js +27 -0
- package/dist/mcp/tools/end-session.js.map +1 -0
- package/dist/mcp/tools/get-findings.d.ts +12 -0
- package/dist/mcp/tools/get-findings.js +42 -0
- package/dist/mcp/tools/get-findings.js.map +1 -0
- package/dist/mcp/tools/index.d.ts +17 -0
- package/dist/mcp/tools/index.js +24 -0
- package/dist/mcp/tools/index.js.map +1 -0
- package/dist/mcp/tools/result.d.ts +10 -0
- package/dist/mcp/tools/result.js +20 -0
- package/dist/mcp/tools/result.js.map +1 -0
- package/dist/mcp/tools/send-message.d.ts +11 -0
- package/dist/mcp/tools/send-message.js +31 -0
- package/dist/mcp/tools/send-message.js.map +1 -0
- package/dist/mcp/tools/start-debug.d.ts +12 -0
- package/dist/mcp/tools/start-debug.js +50 -0
- package/dist/mcp/tools/start-debug.js.map +1 -0
- package/dist/services/debug-service.d.ts +133 -0
- package/dist/services/debug-service.js +163 -0
- package/dist/services/debug-service.js.map +1 -0
- package/dist/services/replay.d.ts +102 -0
- package/dist/services/replay.js +184 -0
- package/dist/services/replay.js.map +1 -0
- package/dist/services/session-builder.d.ts +65 -0
- package/dist/services/session-builder.js +198 -0
- package/dist/services/session-builder.js.map +1 -0
- package/dist/services/summarize.d.ts +59 -0
- package/dist/services/summarize.js +93 -0
- package/dist/services/summarize.js.map +1 -0
- package/dist/session/findings-store.d.ts +52 -0
- package/dist/session/findings-store.js +176 -0
- package/dist/session/findings-store.js.map +1 -0
- package/dist/session/manager.d.ts +47 -0
- package/dist/session/manager.js +66 -0
- package/dist/session/manager.js.map +1 -0
- package/dist/session/process-identity.d.ts +45 -0
- package/dist/session/process-identity.js +81 -0
- package/dist/session/process-identity.js.map +1 -0
- package/dist/session/session.d.ts +156 -0
- package/dist/session/session.js +309 -0
- package/dist/session/session.js.map +1 -0
- package/dist/session/state-file.d.ts +72 -0
- package/dist/session/state-file.js +104 -0
- package/dist/session/state-file.js.map +1 -0
- package/dist/session/workspace.d.ts +60 -0
- package/dist/session/workspace.js +75 -0
- package/dist/session/workspace.js.map +1 -0
- package/package.json +53 -0
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser adapter — drives a Chrome page over CDP via Playwright.
|
|
3
|
+
*
|
|
4
|
+
* Two lifecycles (see `idea/adapters.md`):
|
|
5
|
+
* - **managed** (default): launch a persistent context with the per-project
|
|
6
|
+
* profile; we OWN start/stop. `executablePath` picks the binary, else system
|
|
7
|
+
* Chrome (`channel`) — `playwright-core` ships no bundled browser.
|
|
8
|
+
* - **attach**: connect to an already-running browser over CDP (`cdpUrl`) and
|
|
9
|
+
* NEVER start/stop it — `close()` only disconnects.
|
|
10
|
+
*
|
|
11
|
+
* Implements the shared {@link Adapter} contract over the DOM/a11y: every element
|
|
12
|
+
* normalizes to a {@link Node} (role/name/bounds/enabled) via one batched in-page
|
|
13
|
+
* extraction. Console/network capture is wired by the CDP capture module (next).
|
|
14
|
+
*
|
|
15
|
+
* Fails loud — every Playwright call is wrapped to throw {@link AdapterError},
|
|
16
|
+
* never a silent fallback.
|
|
17
|
+
*/
|
|
18
|
+
import { URL } from 'node:url';
|
|
19
|
+
import { chromium } from 'playwright-core';
|
|
20
|
+
import { AdapterError } from '../../errors.js';
|
|
21
|
+
import { CdpCapture } from './cdp.js';
|
|
22
|
+
import { normalizeQuery } from './query.js';
|
|
23
|
+
/** System Chrome channel used when no explicit `executablePath` is configured. */
|
|
24
|
+
const DEFAULT_CHANNEL = 'chrome';
|
|
25
|
+
/** Default cap on `readState` so the tree stays small (overridable via `limit`). */
|
|
26
|
+
const DEFAULT_LIMIT = 200;
|
|
27
|
+
/** One wheel step (CSS px) when `scroll` is called without an explicit `amount` — page-ish. */
|
|
28
|
+
const DEFAULT_SCROLL_STEP = 600;
|
|
29
|
+
/** Interactive + semantic elements `readState` surfaces when no `query` is given. */
|
|
30
|
+
const DEFAULT_SELECTOR = 'a[href], button, input, select, textarea, [role], [tabindex], [onclick], [contenteditable="true"], summary, label, h1, h2, h3, h4, h5, h6';
|
|
31
|
+
/** Whitelisted `filters` keys for this adapter — anything else is rejected, not ignored. */
|
|
32
|
+
export const NODE_FILTER_KEYS = ['visible_eq', 'enabled_eq', 'role_in', 'name_contains'];
|
|
33
|
+
/**
|
|
34
|
+
* Browser-side element → {@link RawNode} extractor. Playwright serializes this and
|
|
35
|
+
* runs it in the page, so it MUST stay self-contained: no module references, only
|
|
36
|
+
* its params and nested locals. One batched call powers both `find` and
|
|
37
|
+
* `readState`.
|
|
38
|
+
*/
|
|
39
|
+
const NODE_EXTRACTOR = (elements) => {
|
|
40
|
+
const clean = (s) => (s ?? '').replace(/\s+/g, ' ').trim();
|
|
41
|
+
const implicitRole = (el) => {
|
|
42
|
+
const tag = el.tagName.toLowerCase();
|
|
43
|
+
if (tag === 'a')
|
|
44
|
+
return el.hasAttribute('href') ? 'link' : 'generic';
|
|
45
|
+
if (tag === 'select')
|
|
46
|
+
return 'combobox';
|
|
47
|
+
if (tag === 'textarea')
|
|
48
|
+
return 'textbox';
|
|
49
|
+
if (tag === 'input') {
|
|
50
|
+
const type = (el.getAttribute('type') ?? 'text').toLowerCase();
|
|
51
|
+
if (type === 'checkbox' || type === 'radio')
|
|
52
|
+
return type;
|
|
53
|
+
if (type === 'range')
|
|
54
|
+
return 'slider';
|
|
55
|
+
if (type === 'button' || type === 'submit' || type === 'reset' || type === 'image') {
|
|
56
|
+
return 'button';
|
|
57
|
+
}
|
|
58
|
+
return 'textbox';
|
|
59
|
+
}
|
|
60
|
+
if (tag === 'button')
|
|
61
|
+
return 'button';
|
|
62
|
+
if (tag === 'img')
|
|
63
|
+
return 'img';
|
|
64
|
+
if (tag === 'nav')
|
|
65
|
+
return 'navigation';
|
|
66
|
+
if (tag === 'main')
|
|
67
|
+
return 'main';
|
|
68
|
+
if (tag === 'form')
|
|
69
|
+
return 'form';
|
|
70
|
+
if (tag === 'h1' ||
|
|
71
|
+
tag === 'h2' ||
|
|
72
|
+
tag === 'h3' ||
|
|
73
|
+
tag === 'h4' ||
|
|
74
|
+
tag === 'h5' ||
|
|
75
|
+
tag === 'h6') {
|
|
76
|
+
return 'heading';
|
|
77
|
+
}
|
|
78
|
+
return tag;
|
|
79
|
+
};
|
|
80
|
+
const accessibleName = (el) => {
|
|
81
|
+
const label = clean(el.getAttribute('aria-label'));
|
|
82
|
+
if (label)
|
|
83
|
+
return label;
|
|
84
|
+
const labelledby = el.getAttribute('aria-labelledby');
|
|
85
|
+
if (labelledby) {
|
|
86
|
+
const text = clean(labelledby
|
|
87
|
+
.split(/\s+/)
|
|
88
|
+
.map((id) => el.ownerDocument.getElementById(id)?.textContent ?? '')
|
|
89
|
+
.join(' '));
|
|
90
|
+
if (text)
|
|
91
|
+
return text;
|
|
92
|
+
}
|
|
93
|
+
if (el.labels && el.labels.length > 0) {
|
|
94
|
+
const text = clean(Array.from(el.labels)
|
|
95
|
+
.map((l) => l.textContent ?? '')
|
|
96
|
+
.join(' '));
|
|
97
|
+
if (text)
|
|
98
|
+
return text;
|
|
99
|
+
}
|
|
100
|
+
const placeholder = clean(el.getAttribute('placeholder'));
|
|
101
|
+
if (placeholder)
|
|
102
|
+
return placeholder;
|
|
103
|
+
const alt = clean(el.getAttribute('alt'));
|
|
104
|
+
if (alt)
|
|
105
|
+
return alt;
|
|
106
|
+
const text = clean(el.textContent);
|
|
107
|
+
if (text)
|
|
108
|
+
return text;
|
|
109
|
+
const value = clean(el.getAttribute('value'));
|
|
110
|
+
if (value)
|
|
111
|
+
return value;
|
|
112
|
+
return clean(el.getAttribute('title'));
|
|
113
|
+
};
|
|
114
|
+
return elements.map((el) => {
|
|
115
|
+
const r = el.getBoundingClientRect();
|
|
116
|
+
const style = getComputedStyle(el);
|
|
117
|
+
return {
|
|
118
|
+
role: clean(el.getAttribute('role')) || implicitRole(el),
|
|
119
|
+
name: accessibleName(el),
|
|
120
|
+
bounds: {
|
|
121
|
+
x: Math.round(r.x),
|
|
122
|
+
y: Math.round(r.y),
|
|
123
|
+
width: Math.round(r.width),
|
|
124
|
+
height: Math.round(r.height),
|
|
125
|
+
},
|
|
126
|
+
enabled: el.disabled !== true && el.getAttribute('aria-disabled') !== 'true',
|
|
127
|
+
visible: r.width > 0 &&
|
|
128
|
+
r.height > 0 &&
|
|
129
|
+
style.display !== 'none' &&
|
|
130
|
+
style.visibility !== 'hidden' &&
|
|
131
|
+
!el.hasAttribute('hidden') &&
|
|
132
|
+
el.getAttribute('aria-hidden') !== 'true',
|
|
133
|
+
};
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
/** Append the login-bypass query param (`?<param>=true`) when `debugLogin` is configured. */
|
|
137
|
+
export function appendDebugLogin(target, debugLogin) {
|
|
138
|
+
if (!debugLogin)
|
|
139
|
+
return target;
|
|
140
|
+
const url = new URL(target);
|
|
141
|
+
url.searchParams.set(debugLogin.param, 'true');
|
|
142
|
+
return url.toString();
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Map a {@link ScrollDirection} + pixel `amount` onto Playwright wheel deltas
|
|
146
|
+
* `[deltaX, deltaY]` (the viewport scrolls toward that edge). Fails loud on an
|
|
147
|
+
* unrecognized direction — the switch is exhaustive over the union, so a bad
|
|
148
|
+
* value can only arrive from an unchecked boundary.
|
|
149
|
+
*/
|
|
150
|
+
export function scrollDelta(direction, amount) {
|
|
151
|
+
switch (direction) {
|
|
152
|
+
case 'up':
|
|
153
|
+
return [0, -amount];
|
|
154
|
+
case 'down':
|
|
155
|
+
return [0, amount];
|
|
156
|
+
case 'left':
|
|
157
|
+
return [-amount, 0];
|
|
158
|
+
case 'right':
|
|
159
|
+
return [amount, 0];
|
|
160
|
+
default: {
|
|
161
|
+
const unreachable = direction;
|
|
162
|
+
throw new AdapterError(`unknown scroll direction: ${JSON.stringify(unreachable)}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function expectBoolean(key, value) {
|
|
167
|
+
if (typeof value !== 'boolean') {
|
|
168
|
+
throw new AdapterError(`filter \`${key}\` expects a boolean`);
|
|
169
|
+
}
|
|
170
|
+
return value;
|
|
171
|
+
}
|
|
172
|
+
function expectString(key, value) {
|
|
173
|
+
if (typeof value !== 'string') {
|
|
174
|
+
throw new AdapterError(`filter \`${key}\` expects a string`);
|
|
175
|
+
}
|
|
176
|
+
return value;
|
|
177
|
+
}
|
|
178
|
+
function expectStringArray(key, value) {
|
|
179
|
+
if (!Array.isArray(value) || value.some((v) => typeof v !== 'string')) {
|
|
180
|
+
throw new AdapterError(`filter \`${key}\` expects a string[]`);
|
|
181
|
+
}
|
|
182
|
+
return value;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Apply the whitelisted node `filters` in JS. Throws {@link AdapterError} on an
|
|
186
|
+
* unknown key (no silent injection surface) or a wrong value type.
|
|
187
|
+
*/
|
|
188
|
+
export function applyNodeFilters(nodes, filters) {
|
|
189
|
+
if (!filters)
|
|
190
|
+
return nodes;
|
|
191
|
+
let out = nodes;
|
|
192
|
+
for (const [key, value] of Object.entries(filters)) {
|
|
193
|
+
switch (key) {
|
|
194
|
+
case 'visible_eq': {
|
|
195
|
+
const want = expectBoolean(key, value);
|
|
196
|
+
out = out.filter((n) => n.visible === want);
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
case 'enabled_eq': {
|
|
200
|
+
const want = expectBoolean(key, value);
|
|
201
|
+
out = out.filter((n) => n.enabled === want);
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
case 'role_in': {
|
|
205
|
+
const roles = expectStringArray(key, value);
|
|
206
|
+
out = out.filter((n) => roles.includes(n.role));
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
case 'name_contains': {
|
|
210
|
+
const needle = expectString(key, value).toLowerCase();
|
|
211
|
+
out = out.filter((n) => n.name.toLowerCase().includes(needle));
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
default:
|
|
215
|
+
throw new AdapterError(`unknown filter \`${key}\` for browser adapter (allowed: ${NODE_FILTER_KEYS.join(', ')})`);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return out;
|
|
219
|
+
}
|
|
220
|
+
/** True when a node's center sits inside `region` — used to scope by a {@link Node} `within`. */
|
|
221
|
+
function centerWithin(node, region) {
|
|
222
|
+
const cx = node.bounds.x + node.bounds.width / 2;
|
|
223
|
+
const cy = node.bounds.y + node.bounds.height / 2;
|
|
224
|
+
return (cx >= region.x &&
|
|
225
|
+
cx <= region.x + region.width &&
|
|
226
|
+
cy >= region.y &&
|
|
227
|
+
cy <= region.y + region.height);
|
|
228
|
+
}
|
|
229
|
+
/** Drop the internal `visible` flag — the public contract returns plain {@link Node}s. */
|
|
230
|
+
function toNode(node) {
|
|
231
|
+
return { role: node.role, name: node.name, bounds: node.bounds, enabled: node.enabled };
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* The web {@link Adapter}: a Playwright-driven Chrome page. Construct via
|
|
235
|
+
* {@link BrowserAdapter.create} (async launch/connect can't live in a constructor).
|
|
236
|
+
*/
|
|
237
|
+
export class BrowserAdapter {
|
|
238
|
+
#config;
|
|
239
|
+
#context;
|
|
240
|
+
#page;
|
|
241
|
+
#browser;
|
|
242
|
+
#mode;
|
|
243
|
+
#capture;
|
|
244
|
+
constructor(handles) {
|
|
245
|
+
this.#config = handles.config;
|
|
246
|
+
this.#context = handles.context;
|
|
247
|
+
this.#page = handles.page;
|
|
248
|
+
this.#browser = handles.browser;
|
|
249
|
+
this.#mode = handles.mode;
|
|
250
|
+
this.#capture = handles.capture;
|
|
251
|
+
}
|
|
252
|
+
/** Open the adapter: attach over `cdpUrl` when set, else launch a managed persistent context. */
|
|
253
|
+
static async create(init) {
|
|
254
|
+
return init.config.cdpUrl
|
|
255
|
+
? BrowserAdapter.#attach(init.config, init.onLog)
|
|
256
|
+
: BrowserAdapter.#launch(init.config, init.profileDir, init.onLog);
|
|
257
|
+
}
|
|
258
|
+
static async #launch(config, profileDir, onLog) {
|
|
259
|
+
// Still CDP: Playwright drives Chromium exclusively over the DevTools Protocol
|
|
260
|
+
// (here a CDP pipe; `#attach` uses a CDP WebSocket). A persistent context is the
|
|
261
|
+
// supported way to own a Chrome process WITH the per-project profile — both
|
|
262
|
+
// managed and attach speak the same protocol, only the transport differs.
|
|
263
|
+
const context = await chromium.launchPersistentContext(profileDir, {
|
|
264
|
+
headless: config.headless,
|
|
265
|
+
...(config.executablePath
|
|
266
|
+
? { executablePath: config.executablePath }
|
|
267
|
+
: { channel: DEFAULT_CHANNEL }),
|
|
268
|
+
});
|
|
269
|
+
const page = context.pages()[0] ?? (await context.newPage());
|
|
270
|
+
const capture = BrowserAdapter.#startCapture(page, onLog);
|
|
271
|
+
return new BrowserAdapter({ config, context, page, browser: null, mode: 'managed', capture });
|
|
272
|
+
}
|
|
273
|
+
static async #attach(config, onLog) {
|
|
274
|
+
if (!config.cdpUrl) {
|
|
275
|
+
throw new AdapterError('attach mode requires `cdpUrl`');
|
|
276
|
+
}
|
|
277
|
+
const browser = await chromium.connectOverCDP(config.cdpUrl);
|
|
278
|
+
const context = browser.contexts()[0] ?? (await browser.newContext());
|
|
279
|
+
const page = context.pages()[0] ?? (await context.newPage());
|
|
280
|
+
const capture = BrowserAdapter.#startCapture(page, onLog);
|
|
281
|
+
return new BrowserAdapter({ config, context, page, browser, mode: 'attach', capture });
|
|
282
|
+
}
|
|
283
|
+
/** Wire console/network capture onto the live page before the first navigation. */
|
|
284
|
+
static #startCapture(page, onLog) {
|
|
285
|
+
const capture = new CdpCapture({ page, sink: onLog });
|
|
286
|
+
capture.start();
|
|
287
|
+
return capture;
|
|
288
|
+
}
|
|
289
|
+
async open(target) {
|
|
290
|
+
const url = appendDebugLogin(target, this.#config.debugLogin);
|
|
291
|
+
await this.#run('open', async () => {
|
|
292
|
+
await this.#page.goto(url);
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
async find(opts) {
|
|
296
|
+
return this.#run('find', async () => {
|
|
297
|
+
const nodes = await this.#collect({ ...opts, limit: 1 });
|
|
298
|
+
return nodes[0] ?? null;
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
async click(target) {
|
|
302
|
+
await this.#run('click', async () => {
|
|
303
|
+
if (typeof target === 'string') {
|
|
304
|
+
await this.#page.locator(normalizeQuery(target)).first().click();
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
const { x, y, width, height } = target.bounds;
|
|
308
|
+
await this.#page.mouse.click(x + width / 2, y + height / 2);
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
async type(target, text) {
|
|
312
|
+
// Same semantics for both NodeRef forms: focus the target, then type into it
|
|
313
|
+
// (the contract is "focuses it first"). A selector focuses via click rather
|
|
314
|
+
// than `fill()` so it appends like the coordinate path instead of replacing.
|
|
315
|
+
await this.#run('type', async () => {
|
|
316
|
+
if (typeof target === 'string') {
|
|
317
|
+
await this.#page.locator(normalizeQuery(target)).first().click();
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
const { x, y, width, height } = target.bounds;
|
|
321
|
+
await this.#page.mouse.click(x + width / 2, y + height / 2);
|
|
322
|
+
}
|
|
323
|
+
await this.#page.keyboard.type(text);
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
async pressKey(key) {
|
|
327
|
+
if (key.trim() === '') {
|
|
328
|
+
throw new AdapterError('pressKey requires a non-empty key');
|
|
329
|
+
}
|
|
330
|
+
// Playwright's `press` parses chords from the `+`-joined string (`Control+A`):
|
|
331
|
+
// it holds the modifiers while tapping the final key, and throws on an unknown
|
|
332
|
+
// key — both surfaced loud via `#run` (CDP `Input.dispatchKeyEvent` underneath).
|
|
333
|
+
await this.#run('pressKey', async () => {
|
|
334
|
+
await this.#page.keyboard.press(key);
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
async scroll(opts) {
|
|
338
|
+
const [dx, dy] = scrollDelta(opts.direction, opts.amount ?? DEFAULT_SCROLL_STEP);
|
|
339
|
+
await this.#run('scroll', async () => {
|
|
340
|
+
// Scope: park the cursor over the region first, so the wheel event targets the
|
|
341
|
+
// scrollable element under it instead of the viewport. No scope → wheel where
|
|
342
|
+
// the mouse already is (`Input.dispatchMouseEvent` of type `mouseWheel`).
|
|
343
|
+
if (opts.within !== undefined) {
|
|
344
|
+
const { x, y, width, height } = await this.#regionBox(opts.within);
|
|
345
|
+
await this.#page.mouse.move(x + width / 2, y + height / 2);
|
|
346
|
+
}
|
|
347
|
+
await this.#page.mouse.wheel(dx, dy);
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
async readState(opts = {}) {
|
|
351
|
+
return this.#run('readState', () => this.#collect(opts, DEFAULT_LIMIT));
|
|
352
|
+
}
|
|
353
|
+
async screenshot() {
|
|
354
|
+
return this.#run('screenshot', async () => {
|
|
355
|
+
const buffer = await this.#page.screenshot({ type: 'png' });
|
|
356
|
+
return new Uint8Array(buffer);
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
async waitFor(opts) {
|
|
360
|
+
if (!opts.query && !opts.networkIdle) {
|
|
361
|
+
throw new AdapterError('waitFor requires `query` and/or `networkIdle`');
|
|
362
|
+
}
|
|
363
|
+
await this.#run('waitFor', async () => {
|
|
364
|
+
if (opts.query) {
|
|
365
|
+
await this.#page
|
|
366
|
+
.locator(normalizeQuery(opts.query))
|
|
367
|
+
.first()
|
|
368
|
+
.waitFor({ state: 'visible', timeout: opts.timeout });
|
|
369
|
+
}
|
|
370
|
+
if (opts.networkIdle) {
|
|
371
|
+
await this.#page.waitForLoadState('networkidle', { timeout: opts.timeout });
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
async console(opts) {
|
|
376
|
+
return this.#capture.console(opts);
|
|
377
|
+
}
|
|
378
|
+
async network(opts) {
|
|
379
|
+
return this.#capture.network(opts);
|
|
380
|
+
}
|
|
381
|
+
async close() {
|
|
382
|
+
// Detach capture first so no events fire mid-teardown.
|
|
383
|
+
this.#capture.stop();
|
|
384
|
+
await this.#run('close', async () => {
|
|
385
|
+
if (this.#mode === 'attach') {
|
|
386
|
+
// Attach: disconnect only — never stop a browser we did not start.
|
|
387
|
+
if (this.#browser)
|
|
388
|
+
await this.#browser.close();
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
// Managed: close the persistent context we own (stops the browser).
|
|
392
|
+
await this.#context.close();
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
/** Build, scope, filter, and cap the normalized node list shared by `find`/`readState`. */
|
|
396
|
+
async #collect(opts, defaultLimit) {
|
|
397
|
+
// Agent queries are role+name / plain text (what the tree shows), not raw CSS —
|
|
398
|
+
// normalize them onto a Playwright engine; an absent query reads the default set.
|
|
399
|
+
const selector = opts.query ? normalizeQuery(opts.query) : DEFAULT_SELECTOR;
|
|
400
|
+
const scope = typeof opts.within === 'string'
|
|
401
|
+
? this.#page.locator(normalizeQuery(opts.within))
|
|
402
|
+
: this.#page;
|
|
403
|
+
let nodes = await scope.locator(selector).evaluateAll(NODE_EXTRACTOR);
|
|
404
|
+
if (opts.within && typeof opts.within !== 'string') {
|
|
405
|
+
const region = opts.within.bounds;
|
|
406
|
+
nodes = nodes.filter((n) => centerWithin(n, region));
|
|
407
|
+
}
|
|
408
|
+
nodes = applyNodeFilters(nodes, opts.filters);
|
|
409
|
+
const limit = opts.limit ?? defaultLimit;
|
|
410
|
+
if (limit !== undefined)
|
|
411
|
+
nodes = nodes.slice(0, limit);
|
|
412
|
+
return nodes.map(toNode);
|
|
413
|
+
}
|
|
414
|
+
/** Resolve a scroll `within` scope to an on-screen rectangle (Node bounds, or a located selector). */
|
|
415
|
+
async #regionBox(within) {
|
|
416
|
+
if (typeof within !== 'string')
|
|
417
|
+
return within.bounds;
|
|
418
|
+
const box = await this.#page.locator(normalizeQuery(within)).first().boundingBox();
|
|
419
|
+
if (!box) {
|
|
420
|
+
throw new AdapterError(`scroll \`within\` target not found or not visible: ${within}`);
|
|
421
|
+
}
|
|
422
|
+
return box;
|
|
423
|
+
}
|
|
424
|
+
/** Run a Playwright call, re-throwing any failure as a loud {@link AdapterError}. */
|
|
425
|
+
async #run(op, fn) {
|
|
426
|
+
try {
|
|
427
|
+
return await fn();
|
|
428
|
+
}
|
|
429
|
+
catch (error) {
|
|
430
|
+
throw new AdapterError(`browser.${op} failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
//# sourceMappingURL=browser-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-adapter.js","sourceRoot":"","sources":["../../../src/adapters/browser/browser-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;A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C,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,WAAW,EAAE,CAAC;QACnF,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,MAAM,IAAI,YAAY,CAAC,sDAAsD,MAAM,EAAE,CAAC,CAAC;QACzF,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IAED,qFAAqF;IACrF,KAAK,CAAC,IAAI,CAAI,EAAU,EAAE,EAAoB;QAC5C,IAAI,CAAC;YACH,OAAO,MAAM,EAAE,EAAE,CAAC;QACpB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,YAAY,CACpB,WAAW,EAAE,YAAY,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAClF,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CDP console + network capture — the browser adapter's passive observers.
|
|
3
|
+
*
|
|
4
|
+
* Subscribes to Playwright/CDP events the moment the adapter opens and keeps a
|
|
5
|
+
* bounded, in-memory ring of normalized entries:
|
|
6
|
+
* - `page.on('console')` → {@link ConsoleEntry} (severity normalized)
|
|
7
|
+
* - `page.on('pageerror')` → {@link ConsoleEntry} at `level: 'error'` (uncaught
|
|
8
|
+
* exceptions never surface as console messages, but the contract says
|
|
9
|
+
* console capture covers them — so we fold them in)
|
|
10
|
+
* - `page.on('requestfailed')` → {@link NetworkEntry} (`status: 0`, `ok: false`)
|
|
11
|
+
* - `page.on('response')` → {@link NetworkEntry} (covers 4xx/5xx too)
|
|
12
|
+
*
|
|
13
|
+
* Every listener is scoped to the SELECTED page, not the context — an attach or
|
|
14
|
+
* persistent session can hold unrelated tabs, and their traffic must not leak
|
|
15
|
+
* into this run's `network()`.
|
|
16
|
+
*
|
|
17
|
+
* Each captured entry is ALSO streamed line-by-line to an optional {@link CaptureSink}
|
|
18
|
+
* (the session layer wires it to `findings-store`'s `logs/console.log` /
|
|
19
|
+
* `logs/network.log`), so the persistent trail and the live buffer stay in sync.
|
|
20
|
+
*
|
|
21
|
+
* Reads are non-destructive and SQL-like: `console`/`network` return newest-first,
|
|
22
|
+
* narrowed by the whitelisted {@link LogQuery.filters} and capped by `limit`. The
|
|
23
|
+
* buffer is the source of truth for the agent's `observe`; the on-disk log is the
|
|
24
|
+
* durable record. Filters fail loud — an unknown key or wrong value type throws
|
|
25
|
+
* {@link AdapterError}, never a silent ignore.
|
|
26
|
+
*/
|
|
27
|
+
import type { Page } from 'playwright-core';
|
|
28
|
+
import type { ConsoleEntry, Filters, LogQuery, NetworkEntry } from '../contract.js';
|
|
29
|
+
/** Whitelisted `filters` keys for the console channel — anything else is rejected. */
|
|
30
|
+
export declare const CONSOLE_FILTER_KEYS: readonly ["level_eq", "level_in", "text_contains"];
|
|
31
|
+
/** Whitelisted `filters` keys for the network channel — anything else is rejected. */
|
|
32
|
+
export declare const NETWORK_FILTER_KEYS: readonly ["status_eq", "status_gte", "status_lt", "ok_eq", "failed_eq", "method_eq", "resource_in", "url_contains"];
|
|
33
|
+
/**
|
|
34
|
+
* Where captured entries are streamed as formatted log lines. The session layer
|
|
35
|
+
* binds this to `findings-store`'s append-only `console`/`network` channels; the
|
|
36
|
+
* adapter stays decoupled from the session (depends on this seam, not the store).
|
|
37
|
+
*/
|
|
38
|
+
export type CaptureSink = (channel: 'console' | 'network', line: string) => void;
|
|
39
|
+
export interface CdpCaptureInit {
|
|
40
|
+
/** Page that emits `console`/`pageerror`/`requestfailed`/`response`. */
|
|
41
|
+
page: Page;
|
|
42
|
+
/** Optional log sink — each new entry is streamed here as a line. */
|
|
43
|
+
sink?: CaptureSink;
|
|
44
|
+
/** Injected clock (epoch ms) for deterministic capture timestamps; default `Date.now`. */
|
|
45
|
+
now?: () => number;
|
|
46
|
+
/** Per-channel ring size; default {@link DEFAULT_BUFFER_CAP}. */
|
|
47
|
+
cap?: number;
|
|
48
|
+
}
|
|
49
|
+
/** Map a CDP console `type()` onto the normalized {@link ConsoleEntry} level. */
|
|
50
|
+
export declare function normalizeConsoleLevel(type: string): ConsoleEntry['level'];
|
|
51
|
+
/** Render a {@link ConsoleEntry} as one greppable `logs/console.log` line. */
|
|
52
|
+
export declare function formatConsoleLine(entry: ConsoleEntry): string;
|
|
53
|
+
/** Render a {@link NetworkEntry} as one greppable `logs/network.log` line. */
|
|
54
|
+
export declare function formatNetworkLine(entry: NetworkEntry): string;
|
|
55
|
+
/**
|
|
56
|
+
* Narrow console entries by the whitelisted `filters` keys
|
|
57
|
+
* ({@link CONSOLE_FILTER_KEYS}). Throws {@link AdapterError} on an unknown key
|
|
58
|
+
* (no silent injection surface) or a wrong value type.
|
|
59
|
+
*/
|
|
60
|
+
export declare function filterConsole(entries: ConsoleEntry[], filters?: Filters): ConsoleEntry[];
|
|
61
|
+
/**
|
|
62
|
+
* Narrow network entries by the whitelisted `filters` keys
|
|
63
|
+
* ({@link NETWORK_FILTER_KEYS}). Throws {@link AdapterError} on an unknown key or
|
|
64
|
+
* a wrong value type.
|
|
65
|
+
*/
|
|
66
|
+
export declare function filterNetwork(entries: NetworkEntry[], filters?: Filters): NetworkEntry[];
|
|
67
|
+
/**
|
|
68
|
+
* Captures and buffers console + network activity for one browser adapter.
|
|
69
|
+
* Construct with the open page/context, then {@link CdpCapture.start}; release the
|
|
70
|
+
* listeners with {@link CdpCapture.stop} before the page closes.
|
|
71
|
+
*/
|
|
72
|
+
export declare class CdpCapture {
|
|
73
|
+
#private;
|
|
74
|
+
constructor(init: CdpCaptureInit);
|
|
75
|
+
/** Subscribe to the console/error/network events. Idempotent (a re-`start` is a no-op). */
|
|
76
|
+
start(): void;
|
|
77
|
+
/** Detach every listener. Idempotent; safe to call after the page is gone. */
|
|
78
|
+
stop(): void;
|
|
79
|
+
/** Captured console messages, newest first, narrowed by {@link LogQuery}. */
|
|
80
|
+
console(opts?: LogQuery): ConsoleEntry[];
|
|
81
|
+
/** Captured network exchanges, newest first, narrowed by {@link LogQuery}. */
|
|
82
|
+
network(opts?: LogQuery): NetworkEntry[];
|
|
83
|
+
}
|