@developerz.ai/ui-debugger-mcp 1.1.0 → 1.3.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/README.md +45 -10
- package/dist/adapters/android/adb.d.ts +34 -5
- package/dist/adapters/android/adb.js +74 -20
- package/dist/adapters/android/adb.js.map +1 -1
- package/dist/adapters/android/android-adapter.d.ts +23 -7
- package/dist/adapters/android/android-adapter.js +106 -36
- package/dist/adapters/android/android-adapter.js.map +1 -1
- package/dist/adapters/android/android-adapter.test-helpers.d.ts +52 -0
- package/dist/adapters/android/android-adapter.test-helpers.js +115 -0
- package/dist/adapters/android/android-adapter.test-helpers.js.map +1 -0
- package/dist/adapters/android/commands.d.ts +27 -4
- package/dist/adapters/android/commands.js +66 -4
- package/dist/adapters/android/commands.js.map +1 -1
- package/dist/adapters/android/ports.d.ts +32 -0
- package/dist/adapters/android/ports.js +47 -0
- package/dist/adapters/android/ports.js.map +1 -0
- package/dist/adapters/android/uiautomator.d.ts +10 -2
- package/dist/adapters/android/uiautomator.js +36 -4
- package/dist/adapters/android/uiautomator.js.map +1 -1
- package/dist/adapters/browser/browser-adapter.d.ts +16 -13
- package/dist/adapters/browser/browser-adapter.js +196 -313
- package/dist/adapters/browser/browser-adapter.js.map +1 -1
- package/dist/adapters/browser/cdp.d.ts +40 -2
- package/dist/adapters/browser/cdp.js +223 -19
- package/dist/adapters/browser/cdp.js.map +1 -1
- package/dist/adapters/browser/extractor.d.ts +53 -0
- package/dist/adapters/browser/extractor.js +224 -0
- package/dist/adapters/browser/extractor.js.map +1 -0
- package/dist/adapters/browser/filters.d.ts +15 -0
- package/dist/adapters/browser/filters.js +93 -0
- package/dist/adapters/browser/filters.js.map +1 -0
- package/dist/adapters/browser/launch.d.ts +41 -0
- package/dist/adapters/browser/launch.js +61 -0
- package/dist/adapters/browser/launch.js.map +1 -0
- package/dist/adapters/budget.d.ts +16 -0
- package/dist/adapters/budget.js +25 -0
- package/dist/adapters/budget.js.map +1 -0
- package/dist/adapters/contract.d.ts +82 -6
- package/dist/adapters/desktop/atspi.d.ts +15 -0
- package/dist/adapters/desktop/atspi.js +37 -17
- package/dist/adapters/desktop/atspi.js.map +1 -1
- package/dist/adapters/desktop/capture.js +8 -1
- package/dist/adapters/desktop/capture.js.map +1 -1
- package/dist/adapters/desktop/desktop-adapter.d.ts +9 -2
- package/dist/adapters/desktop/desktop-adapter.js +84 -32
- package/dist/adapters/desktop/desktop-adapter.js.map +1 -1
- package/dist/adapters/desktop/input.d.ts +16 -1
- package/dist/adapters/desktop/input.js +30 -0
- package/dist/adapters/desktop/input.js.map +1 -1
- package/dist/adapters/desktop/proc.d.ts +18 -3
- package/dist/adapters/desktop/proc.js +48 -5
- package/dist/adapters/desktop/proc.js.map +1 -1
- package/dist/adapters/factory.d.ts +3 -1
- package/dist/adapters/factory.js +6 -2
- package/dist/adapters/factory.js.map +1 -1
- package/dist/adapters/limit.d.ts +10 -0
- package/dist/adapters/limit.js +19 -0
- package/dist/adapters/limit.js.map +1 -0
- package/dist/agent/belt/act.d.ts +44 -9
- package/dist/agent/belt/act.js +176 -21
- package/dist/agent/belt/act.js.map +1 -1
- package/dist/agent/belt/look.d.ts +1 -1
- package/dist/agent/belt/look.js +31 -2
- package/dist/agent/belt/look.js.map +1 -1
- package/dist/agent/belt/observe.d.ts +42 -16
- package/dist/agent/belt/observe.js +134 -22
- package/dist/agent/belt/observe.js.map +1 -1
- package/dist/agent/belt/report.d.ts +29 -9
- package/dist/agent/belt/report.js +77 -10
- package/dist/agent/belt/report.js.map +1 -1
- package/dist/agent/belt/trail.d.ts +34 -0
- package/dist/agent/belt/trail.js +64 -0
- package/dist/agent/belt/trail.js.map +1 -0
- package/dist/agent/capabilities.d.ts +4 -4
- package/dist/agent/capabilities.js +41 -13
- package/dist/agent/capabilities.js.map +1 -1
- package/dist/agent/loop.d.ts +70 -21
- package/dist/agent/loop.js +146 -48
- package/dist/agent/loop.js.map +1 -1
- package/dist/agent/prompts/compose.d.ts +9 -1
- package/dist/agent/prompts/compose.js +5 -4
- package/dist/agent/prompts/compose.js.map +1 -1
- package/dist/agent/prompts/debug-agent.d.ts +13 -1
- package/dist/agent/prompts/debug-agent.js +98 -14
- package/dist/agent/prompts/debug-agent.js.map +1 -1
- package/dist/agent/prompts/desktop-addendum.d.ts +1 -1
- package/dist/agent/prompts/desktop-addendum.js +1 -1
- package/dist/agent/prompts/web-addendum.d.ts +1 -1
- package/dist/agent/prompts/web-addendum.js +84 -16
- package/dist/agent/prompts/web-addendum.js.map +1 -1
- package/dist/cli/control.d.ts +3 -1
- package/dist/cli/control.js +26 -40
- package/dist/cli/control.js.map +1 -1
- package/dist/cli/help.d.ts +3 -1
- package/dist/cli/help.js +6 -2
- package/dist/cli/help.js.map +1 -1
- package/dist/cli/init.d.ts +3 -6
- package/dist/cli/init.js +64 -16
- package/dist/cli/init.js.map +1 -1
- package/dist/config/fingerprint.d.ts +32 -0
- package/dist/config/fingerprint.js +47 -0
- package/dist/config/fingerprint.js.map +1 -0
- package/dist/config/load.d.ts +7 -1
- package/dist/config/load.js +17 -4
- package/dist/config/load.js.map +1 -1
- package/dist/config/schema.d.ts +12 -5
- package/dist/config/schema.js +17 -7
- package/dist/config/schema.js.map +1 -1
- package/dist/errors.d.ts +14 -2
- package/dist/errors.js +24 -4
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/main.js +26 -8
- package/dist/main.js.map +1 -1
- package/dist/mcp/server.d.ts +16 -1
- package/dist/mcp/server.js +23 -2
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/server.test-helpers.d.ts +23 -0
- package/dist/mcp/server.test-helpers.js +49 -0
- package/dist/mcp/server.test-helpers.js.map +1 -0
- package/dist/mcp/tools/describe.js +5 -0
- package/dist/mcp/tools/describe.js.map +1 -1
- package/dist/mcp/tools/end-session.js +5 -0
- package/dist/mcp/tools/end-session.js.map +1 -1
- package/dist/mcp/tools/get-findings.js +23 -3
- package/dist/mcp/tools/get-findings.js.map +1 -1
- package/dist/mcp/tools/output.d.ts +50 -0
- package/dist/mcp/tools/output.js +55 -0
- package/dist/mcp/tools/output.js.map +1 -0
- package/dist/mcp/tools/result.d.ts +24 -1
- package/dist/mcp/tools/result.js +106 -5
- package/dist/mcp/tools/result.js.map +1 -1
- package/dist/mcp/tools/send-message.js +5 -0
- package/dist/mcp/tools/send-message.js.map +1 -1
- package/dist/mcp/tools/start-debug.js +7 -1
- package/dist/mcp/tools/start-debug.js.map +1 -1
- package/dist/services/debug-service.d.ts +47 -8
- package/dist/services/debug-service.js +185 -14
- package/dist/services/debug-service.js.map +1 -1
- package/dist/services/session-builder.d.ts +20 -3
- package/dist/services/session-builder.js +43 -13
- package/dist/services/session-builder.js.map +1 -1
- package/dist/services/summarize.d.ts +1 -1
- package/dist/services/summarize.js +8 -1
- package/dist/services/summarize.js.map +1 -1
- package/dist/session/atomic-write.d.ts +24 -0
- package/dist/session/atomic-write.js +39 -0
- package/dist/session/atomic-write.js.map +1 -0
- package/dist/session/findings-store.js +3 -4
- package/dist/session/findings-store.js.map +1 -1
- package/dist/session/process-identity.d.ts +16 -0
- package/dist/session/process-identity.js +29 -0
- package/dist/session/process-identity.js.map +1 -1
- package/dist/session/session.js +36 -4
- package/dist/session/session.js.map +1 -1
- package/dist/session/state-file.d.ts +64 -5
- package/dist/session/state-file.js +76 -9
- package/dist/session/state-file.js.map +1 -1
- package/dist/session/workspace.d.ts +11 -0
- package/dist/session/workspace.js +14 -1
- package/dist/session/workspace.js.map +1 -1
- package/package.json +4 -1
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-side element → {@link RawNode} extraction. Split out of `browser-adapter.ts`
|
|
3
|
+
* to keep that file under the 500-LOC cap — no behavior change.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Browser-side element → {@link RawNode} extractor. Playwright serializes this and
|
|
7
|
+
* runs it in the page, so it MUST stay self-contained: no module references, only
|
|
8
|
+
* its params and nested locals. One batched call powers both `find` and
|
|
9
|
+
* `readState`.
|
|
10
|
+
*/
|
|
11
|
+
export const NODE_EXTRACTOR = (elements) => {
|
|
12
|
+
const clean = (s) => (s ?? '').replace(/\s+/g, ' ').trim();
|
|
13
|
+
const parseColor = (value) => {
|
|
14
|
+
const m = /^rgba?\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)(?:[,\s/]+([\d.]+%?))?\s*\)$/.exec(value ?? '');
|
|
15
|
+
if (!m?.[1] || !m[2] || !m[3])
|
|
16
|
+
return null;
|
|
17
|
+
const rawAlpha = m[4];
|
|
18
|
+
const a = rawAlpha === undefined
|
|
19
|
+
? 1
|
|
20
|
+
: rawAlpha.endsWith('%')
|
|
21
|
+
? Number.parseFloat(rawAlpha) / 100
|
|
22
|
+
: Number.parseFloat(rawAlpha);
|
|
23
|
+
return {
|
|
24
|
+
r: Number.parseFloat(m[1]),
|
|
25
|
+
g: Number.parseFloat(m[2]),
|
|
26
|
+
b: Number.parseFloat(m[3]),
|
|
27
|
+
a,
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
// The viewport canvas ("backplate") — the fallback background when no opaque
|
|
31
|
+
// ancestor paints one. Browsers DARKEN this backplate for pages that opt into
|
|
32
|
+
// `color-scheme: dark`, so hard-coding white would mis-judge contrast there.
|
|
33
|
+
// Resolve the CSS system `Canvas` color under the root's used color scheme via
|
|
34
|
+
// a throwaway probe (appended + removed in the same synchronous turn — never
|
|
35
|
+
// painted), degrading to white when `Canvas` is unsupported. Cached: one probe
|
|
36
|
+
// per extraction, not per node.
|
|
37
|
+
let canvasFallback;
|
|
38
|
+
const canvasBackground = (doc) => {
|
|
39
|
+
if (canvasFallback)
|
|
40
|
+
return canvasFallback;
|
|
41
|
+
const probe = doc.createElement('div');
|
|
42
|
+
probe.style.backgroundColor = 'Canvas';
|
|
43
|
+
doc.documentElement.appendChild(probe);
|
|
44
|
+
const resolved = parseColor(getComputedStyle(probe).backgroundColor);
|
|
45
|
+
doc.documentElement.removeChild(probe);
|
|
46
|
+
canvasFallback = resolved && resolved.a >= 0.99 ? resolved : { r: 255, g: 255, b: 255, a: 1 };
|
|
47
|
+
return canvasFallback;
|
|
48
|
+
};
|
|
49
|
+
// Nearest opaque ancestor background; else the actual viewport canvas color.
|
|
50
|
+
const effectiveBackground = (el) => {
|
|
51
|
+
let node = el;
|
|
52
|
+
while (node) {
|
|
53
|
+
const bg = parseColor(getComputedStyle(node).backgroundColor);
|
|
54
|
+
if (bg && bg.a >= 0.99)
|
|
55
|
+
return bg;
|
|
56
|
+
node = node.parentElement;
|
|
57
|
+
}
|
|
58
|
+
return canvasBackground(el.ownerDocument);
|
|
59
|
+
};
|
|
60
|
+
const luminance = (c) => {
|
|
61
|
+
const chan = (v) => {
|
|
62
|
+
const s = v / 255;
|
|
63
|
+
return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
|
|
64
|
+
};
|
|
65
|
+
return 0.2126 * chan(c.r) + 0.7152 * chan(c.g) + 0.0722 * chan(c.b);
|
|
66
|
+
};
|
|
67
|
+
// WCAG ratio (1–21), with a translucent foreground blended over the background.
|
|
68
|
+
const contrastRatio = (fg, bg) => {
|
|
69
|
+
const blended = fg.a >= 1
|
|
70
|
+
? fg
|
|
71
|
+
: {
|
|
72
|
+
r: fg.r * fg.a + bg.r * (1 - fg.a),
|
|
73
|
+
g: fg.g * fg.a + bg.g * (1 - fg.a),
|
|
74
|
+
b: fg.b * fg.a + bg.b * (1 - fg.a),
|
|
75
|
+
a: 1,
|
|
76
|
+
};
|
|
77
|
+
const l1 = luminance(blended);
|
|
78
|
+
const l2 = luminance(bg);
|
|
79
|
+
const hi = Math.max(l1, l2);
|
|
80
|
+
const lo = Math.min(l1, l2);
|
|
81
|
+
return Math.round(((hi + 0.05) / (lo + 0.05)) * 100) / 100;
|
|
82
|
+
};
|
|
83
|
+
const implicitRole = (el) => {
|
|
84
|
+
const tag = el.tagName.toLowerCase();
|
|
85
|
+
if (tag === 'a')
|
|
86
|
+
return el.hasAttribute('href') ? 'link' : 'generic';
|
|
87
|
+
if (tag === 'select')
|
|
88
|
+
return 'combobox';
|
|
89
|
+
if (tag === 'textarea')
|
|
90
|
+
return 'textbox';
|
|
91
|
+
if (tag === 'input') {
|
|
92
|
+
const type = (el.getAttribute('type') ?? 'text').toLowerCase();
|
|
93
|
+
if (type === 'checkbox' || type === 'radio')
|
|
94
|
+
return type;
|
|
95
|
+
if (type === 'range')
|
|
96
|
+
return 'slider';
|
|
97
|
+
if (type === 'button' || type === 'submit' || type === 'reset' || type === 'image') {
|
|
98
|
+
return 'button';
|
|
99
|
+
}
|
|
100
|
+
return 'textbox';
|
|
101
|
+
}
|
|
102
|
+
if (tag === 'button')
|
|
103
|
+
return 'button';
|
|
104
|
+
if (tag === 'img')
|
|
105
|
+
return 'img';
|
|
106
|
+
if (tag === 'nav')
|
|
107
|
+
return 'navigation';
|
|
108
|
+
if (tag === 'main')
|
|
109
|
+
return 'main';
|
|
110
|
+
if (tag === 'form')
|
|
111
|
+
return 'form';
|
|
112
|
+
if (tag === 'h1' ||
|
|
113
|
+
tag === 'h2' ||
|
|
114
|
+
tag === 'h3' ||
|
|
115
|
+
tag === 'h4' ||
|
|
116
|
+
tag === 'h5' ||
|
|
117
|
+
tag === 'h6') {
|
|
118
|
+
return 'heading';
|
|
119
|
+
}
|
|
120
|
+
return tag;
|
|
121
|
+
};
|
|
122
|
+
const accessibleName = (el) => {
|
|
123
|
+
const label = clean(el.getAttribute('aria-label'));
|
|
124
|
+
if (label)
|
|
125
|
+
return label;
|
|
126
|
+
const labelledby = el.getAttribute('aria-labelledby');
|
|
127
|
+
if (labelledby) {
|
|
128
|
+
const text = clean(labelledby
|
|
129
|
+
.split(/\s+/)
|
|
130
|
+
.map((id) => el.ownerDocument.getElementById(id)?.textContent ?? '')
|
|
131
|
+
.join(' '));
|
|
132
|
+
if (text)
|
|
133
|
+
return text;
|
|
134
|
+
}
|
|
135
|
+
if (el.labels && el.labels.length > 0) {
|
|
136
|
+
const text = clean(Array.from(el.labels)
|
|
137
|
+
.map((l) => l.textContent ?? '')
|
|
138
|
+
.join(' '));
|
|
139
|
+
if (text)
|
|
140
|
+
return text;
|
|
141
|
+
}
|
|
142
|
+
const placeholder = clean(el.getAttribute('placeholder'));
|
|
143
|
+
if (placeholder)
|
|
144
|
+
return placeholder;
|
|
145
|
+
const alt = clean(el.getAttribute('alt'));
|
|
146
|
+
if (alt)
|
|
147
|
+
return alt;
|
|
148
|
+
const text = clean(el.textContent);
|
|
149
|
+
if (text)
|
|
150
|
+
return text;
|
|
151
|
+
const value = clean(el.getAttribute('value'));
|
|
152
|
+
if (value)
|
|
153
|
+
return value;
|
|
154
|
+
return clean(el.getAttribute('title'));
|
|
155
|
+
};
|
|
156
|
+
// Contract: `enabled` is "interactable" — false when disabled OR readonly.
|
|
157
|
+
// - `:disabled` catches the INHERITED state a `disabled` property misses:
|
|
158
|
+
// controls inside `fieldset[disabled]` (bar its first `<legend>`), options
|
|
159
|
+
// under a disabled `<optgroup>`.
|
|
160
|
+
// - `readonly` blocks input without disabling the element, so the driver must
|
|
161
|
+
// see it as not-interactable too (typing there is a no-op it can't explain).
|
|
162
|
+
// Assumption: `readOnly` set on a control where HTML ignores it (checkbox,
|
|
163
|
+
// button) is an authoring mistake — we report it as such rather than guess.
|
|
164
|
+
// - ARIA equivalents cover custom widgets (`div role="textbox"`), which carry
|
|
165
|
+
// no native disabled/readonly state at all.
|
|
166
|
+
const interactable = (el) => !el.matches(':disabled') &&
|
|
167
|
+
el.getAttribute('aria-disabled') !== 'true' &&
|
|
168
|
+
el.readOnly !== true &&
|
|
169
|
+
el.getAttribute('aria-readonly') !== 'true';
|
|
170
|
+
/** Elements that carry live value/checked state worth reporting. */
|
|
171
|
+
const isFormControl = (el) => {
|
|
172
|
+
const tag = el.tagName.toLowerCase();
|
|
173
|
+
return tag === 'input' || tag === 'textarea' || tag === 'select';
|
|
174
|
+
};
|
|
175
|
+
return elements.map((el) => {
|
|
176
|
+
const r = el.getBoundingClientRect();
|
|
177
|
+
const style = getComputedStyle(el);
|
|
178
|
+
const testid = clean(el.getAttribute('data-testid'));
|
|
179
|
+
const text = clean(el.textContent);
|
|
180
|
+
const node = {
|
|
181
|
+
role: clean(el.getAttribute('role')) || implicitRole(el),
|
|
182
|
+
name: accessibleName(el),
|
|
183
|
+
bounds: {
|
|
184
|
+
x: Math.round(r.x),
|
|
185
|
+
y: Math.round(r.y),
|
|
186
|
+
width: Math.round(r.width),
|
|
187
|
+
height: Math.round(r.height),
|
|
188
|
+
},
|
|
189
|
+
enabled: interactable(el),
|
|
190
|
+
visible: r.width > 0 &&
|
|
191
|
+
r.height > 0 &&
|
|
192
|
+
style.display !== 'none' &&
|
|
193
|
+
style.visibility !== 'hidden' &&
|
|
194
|
+
!el.hasAttribute('hidden') &&
|
|
195
|
+
el.getAttribute('aria-hidden') !== 'true',
|
|
196
|
+
};
|
|
197
|
+
if (testid)
|
|
198
|
+
node.testid = testid;
|
|
199
|
+
// Live form state, read off the PROPERTIES. `getAttribute('value')` returns the
|
|
200
|
+
// markup's initial value and never changes as the user types, and `name` resolves
|
|
201
|
+
// to the label/placeholder long before it would reach a value — so before this
|
|
202
|
+
// there was NO structural way to see what a field contained. Drivers fell back to
|
|
203
|
+
// `look` and burned whole runs asking vision "did my text land?".
|
|
204
|
+
if (isFormControl(el)) {
|
|
205
|
+
if (typeof el.value === 'string')
|
|
206
|
+
node.value = el.value;
|
|
207
|
+
if (typeof el.checked === 'boolean')
|
|
208
|
+
node.checked = el.checked;
|
|
209
|
+
}
|
|
210
|
+
if (text) {
|
|
211
|
+
const fg = parseColor(style.color);
|
|
212
|
+
if (fg) {
|
|
213
|
+
const bg = effectiveBackground(el);
|
|
214
|
+
node.style = {
|
|
215
|
+
color: style.color,
|
|
216
|
+
backgroundColor: `rgb(${bg.r}, ${bg.g}, ${bg.b})`,
|
|
217
|
+
contrast: contrastRatio(fg, bg),
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return node;
|
|
222
|
+
});
|
|
223
|
+
};
|
|
224
|
+
//# sourceMappingURL=extractor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../../src/adapters/browser/extractor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAoDH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,QAAiB,EAAa,EAAE;IAC7D,MAAM,KAAK,GAAG,CAAC,CAA4B,EAAU,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IAS9F,MAAM,UAAU,GAAG,CAAC,KAAgC,EAAe,EAAE;QACnE,MAAM,CAAC,GAAG,6EAA6E,CAAC,IAAI,CAC1F,KAAK,IAAI,EAAE,CACZ,CAAC;QACF,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;YAAE,OAAO,IAAI,CAAC;QAC3C,MAAM,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACtB,MAAM,CAAC,GACL,QAAQ,KAAK,SAAS;YACpB,CAAC,CAAC,CAAC;YACH,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;gBACtB,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,GAAG;gBACnC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QACpC,OAAO;YACL,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1B,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1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CAAC,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC;gBAC1B,EAAE,CAAC,YAAY,CAAC,aAAa,CAAC,KAAK,MAAM;SAC5C,CAAC;QACF,IAAI,MAAM;YAAE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACjC,gFAAgF;QAChF,kFAAkF;QAClF,+EAA+E;QAC/E,kFAAkF;QAClF,kEAAkE;QAClE,IAAI,aAAa,CAAC,EAAE,CAAC,EAAE,CAAC;YACtB,IAAI,OAAO,EAAE,CAAC,KAAK,KAAK,QAAQ;gBAAE,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,KAAK,CAAC;YACxD,IAAI,OAAO,EAAE,CAAC,OAAO,KAAK,SAAS;gBAAE,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC;QACjE,CAAC;QACD,IAAI,IAAI,EAAE,CAAC;YACT,MAAM,EAAE,GAAG,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YACnC,IAAI,EAAE,EAAE,CAAC;gBACP,MAAM,EAAE,GAAG,mBAAmB,CAAC,EAAE,CAAC,CAAC;gBACnC,IAAI,CAAC,KAAK,GAAG;oBACX,KAAK,EAAE,KAAK,CAAC,KAAK;oBAClB,eAAe,EAAE,OAAO,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,GAAG;oBACjD,QAAQ,EAAE,aAAa,CAAC,EAAE,EAAE,EAAE,CAAC;iBAChC,CAAC;YACJ,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node-filter application for the browser adapter. Split out of `browser-adapter.ts`
|
|
3
|
+
* to keep that file under the 500-LOC cap — no behavior change.
|
|
4
|
+
*/
|
|
5
|
+
import type { Bounds, Filters } from '../contract.js';
|
|
6
|
+
import type { RawNode } from './extractor.js';
|
|
7
|
+
/** Whitelisted `filters` keys for this adapter — anything else is rejected, not ignored. */
|
|
8
|
+
export declare const NODE_FILTER_KEYS: readonly ["visible_eq", "enabled_eq", "role_in", "name_contains", "contrast_lt"];
|
|
9
|
+
/**
|
|
10
|
+
* Apply the whitelisted node `filters` in JS. Throws {@link AdapterError} on an
|
|
11
|
+
* unknown key (no silent injection surface) or a wrong value type.
|
|
12
|
+
*/
|
|
13
|
+
export declare function applyNodeFilters(nodes: RawNode[], filters?: Filters): RawNode[];
|
|
14
|
+
/** True when a node's center sits inside `region` — used to scope by a {@link Node} `within`. */
|
|
15
|
+
export declare function centerWithin(node: RawNode, region: Bounds): boolean;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node-filter application for the browser adapter. Split out of `browser-adapter.ts`
|
|
3
|
+
* to keep that file under the 500-LOC cap — no behavior change.
|
|
4
|
+
*/
|
|
5
|
+
import { AdapterError } from '../../errors.js';
|
|
6
|
+
/** Whitelisted `filters` keys for this adapter — anything else is rejected, not ignored. */
|
|
7
|
+
export const NODE_FILTER_KEYS = [
|
|
8
|
+
'visible_eq',
|
|
9
|
+
'enabled_eq',
|
|
10
|
+
'role_in',
|
|
11
|
+
'name_contains',
|
|
12
|
+
'contrast_lt',
|
|
13
|
+
];
|
|
14
|
+
function expectBoolean(key, value) {
|
|
15
|
+
if (typeof value !== 'boolean') {
|
|
16
|
+
throw new AdapterError(`filter \`${key}\` expects a boolean`);
|
|
17
|
+
}
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
function expectString(key, value) {
|
|
21
|
+
if (typeof value !== 'string') {
|
|
22
|
+
throw new AdapterError(`filter \`${key}\` expects a string`);
|
|
23
|
+
}
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
function expectNumber(key, value) {
|
|
27
|
+
if (typeof value !== 'number') {
|
|
28
|
+
throw new AdapterError(`filter \`${key}\` expects a number`);
|
|
29
|
+
}
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
function expectStringArray(key, value) {
|
|
33
|
+
if (!Array.isArray(value) || value.some((v) => typeof v !== 'string')) {
|
|
34
|
+
throw new AdapterError(`filter \`${key}\` expects a string[]`);
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Apply the whitelisted node `filters` in JS. Throws {@link AdapterError} on an
|
|
40
|
+
* unknown key (no silent injection surface) or a wrong value type.
|
|
41
|
+
*/
|
|
42
|
+
export function applyNodeFilters(nodes, filters) {
|
|
43
|
+
if (!filters)
|
|
44
|
+
return nodes;
|
|
45
|
+
let out = nodes;
|
|
46
|
+
for (const [key, value] of Object.entries(filters)) {
|
|
47
|
+
switch (key) {
|
|
48
|
+
case 'visible_eq': {
|
|
49
|
+
const want = expectBoolean(key, value);
|
|
50
|
+
out = out.filter((n) => n.visible === want);
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
case 'enabled_eq': {
|
|
54
|
+
const want = expectBoolean(key, value);
|
|
55
|
+
out = out.filter((n) => n.enabled === want);
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
case 'role_in': {
|
|
59
|
+
const roles = expectStringArray(key, value);
|
|
60
|
+
out = out.filter((n) => roles.includes(n.role));
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
case 'name_contains': {
|
|
64
|
+
const needle = expectString(key, value).toLowerCase();
|
|
65
|
+
out = out.filter((n) => n.name.toLowerCase().includes(needle));
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
case 'contrast_lt': {
|
|
69
|
+
// Keep only VISIBLE text nodes whose contrast is BELOW the threshold —
|
|
70
|
+
// the one-call "find unreadable text" sweep runs without `visible_eq`,
|
|
71
|
+
// so hidden nodes with coincidentally low contrast must drop out here or
|
|
72
|
+
// they surface as false "hard-to-read text" findings (nodes without
|
|
73
|
+
// style drop out too).
|
|
74
|
+
const threshold = expectNumber(key, value);
|
|
75
|
+
out = out.filter((n) => n.visible && n.style?.contrast !== undefined && n.style.contrast < threshold);
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
default:
|
|
79
|
+
throw new AdapterError(`unknown filter \`${key}\` for browser adapter (allowed: ${NODE_FILTER_KEYS.join(', ')})`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return out;
|
|
83
|
+
}
|
|
84
|
+
/** True when a node's center sits inside `region` — used to scope by a {@link Node} `within`. */
|
|
85
|
+
export function centerWithin(node, region) {
|
|
86
|
+
const cx = node.bounds.x + node.bounds.width / 2;
|
|
87
|
+
const cy = node.bounds.y + node.bounds.height / 2;
|
|
88
|
+
return (cx >= region.x &&
|
|
89
|
+
cx <= region.x + region.width &&
|
|
90
|
+
cy >= region.y &&
|
|
91
|
+
cy <= region.y + region.height);
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=filters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filters.js","sourceRoot":"","sources":["../../../src/adapters/browser/filters.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAI/C,4FAA4F;AAC5F,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,YAAY;IACZ,YAAY;IACZ,SAAS;IACT,eAAe;IACf,aAAa;CACL,CAAC;AAEX,SAAS,aAAa,CAAC,GAAW,EAAE,KAAkB;IACpD,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;QAC/B,MAAM,IAAI,YAAY,CAAC,YAAY,GAAG,sBAAsB,CAAC,CAAC;IAChE,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,YAAY,CAAC,GAAW,EAAE,KAAkB;IACnD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,IAAI,YAAY,CAAC,YAAY,GAAG,qBAAqB,CAAC,CAAC;IAC/D,CAAC;IACD,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AACjG,MAAM,UAAU,YAAY,CAAC,IAAa,EAAE,MAAc;IACxD,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC;IACjD,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;IAClD,OAAO,CACL,EAAE,IAAI,MAAM,CAAC,CAAC;QACd,EAAE,IAAI,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK;QAC7B,EAAE,IAAI,MAAM,CAAC,CAAC;QACd,EAAE,IAAI,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAC/B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser lifecycle guards — the failure paths of {@link BrowserAdapter.create}.
|
|
3
|
+
*
|
|
4
|
+
* Two rules, both about not poisoning the NEXT run:
|
|
5
|
+
* - **No zombie Chrome.** Anything that throws after the browser is already up
|
|
6
|
+
* must close it before rethrowing. A leaked persistent context keeps holding
|
|
7
|
+
* the per-project profile lock, so every later launch dies on it.
|
|
8
|
+
* - **No raw Playwright errors.** `create` failures leave as {@link AdapterError}
|
|
9
|
+
* like every other adapter call (see the adapter's header contract). The
|
|
10
|
+
* profile-lock case — by far the most common — says how to unblock it.
|
|
11
|
+
*
|
|
12
|
+
* Lives beside the adapter rather than inside it: same reason `query.ts`/`cdp.ts` do.
|
|
13
|
+
*/
|
|
14
|
+
import { AdapterError } from '../../errors.js';
|
|
15
|
+
/** A Playwright handle opened by a lifecycle: the context (managed) or the browser (attach). */
|
|
16
|
+
export interface Closable {
|
|
17
|
+
close(): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Run post-connect setup, closing `handle` if it throws. On success the value is
|
|
21
|
+
* returned untouched and the handle stays open — the caller owns it from then on.
|
|
22
|
+
*
|
|
23
|
+
* A failing `close()` is swallowed on purpose: the setup failure is the real news
|
|
24
|
+
* and a teardown error must not mask it. Best-effort teardown still beats leaking
|
|
25
|
+
* the profile lock.
|
|
26
|
+
*/
|
|
27
|
+
export declare function closeOnFailure<T>(handle: Closable, setup: () => Promise<T>): Promise<T>;
|
|
28
|
+
/** Which lifecycle failed — decides what the error message can usefully point at. */
|
|
29
|
+
export type CreateContext = {
|
|
30
|
+
mode: 'managed';
|
|
31
|
+
profileDir: string;
|
|
32
|
+
} | {
|
|
33
|
+
mode: 'attach';
|
|
34
|
+
cdpUrl: string;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Translate a `create` failure into a loud {@link AdapterError}. An AdapterError
|
|
38
|
+
* passes through as-is — it already names the problem, and double-wrapping would
|
|
39
|
+
* only bury it.
|
|
40
|
+
*/
|
|
41
|
+
export declare function createFailure(error: unknown, ctx: CreateContext): AdapterError;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser lifecycle guards — the failure paths of {@link BrowserAdapter.create}.
|
|
3
|
+
*
|
|
4
|
+
* Two rules, both about not poisoning the NEXT run:
|
|
5
|
+
* - **No zombie Chrome.** Anything that throws after the browser is already up
|
|
6
|
+
* must close it before rethrowing. A leaked persistent context keeps holding
|
|
7
|
+
* the per-project profile lock, so every later launch dies on it.
|
|
8
|
+
* - **No raw Playwright errors.** `create` failures leave as {@link AdapterError}
|
|
9
|
+
* like every other adapter call (see the adapter's header contract). The
|
|
10
|
+
* profile-lock case — by far the most common — says how to unblock it.
|
|
11
|
+
*
|
|
12
|
+
* Lives beside the adapter rather than inside it: same reason `query.ts`/`cdp.ts` do.
|
|
13
|
+
*/
|
|
14
|
+
import { AdapterError } from '../../errors.js';
|
|
15
|
+
/**
|
|
16
|
+
* Run post-connect setup, closing `handle` if it throws. On success the value is
|
|
17
|
+
* returned untouched and the handle stays open — the caller owns it from then on.
|
|
18
|
+
*
|
|
19
|
+
* A failing `close()` is swallowed on purpose: the setup failure is the real news
|
|
20
|
+
* and a teardown error must not mask it. Best-effort teardown still beats leaking
|
|
21
|
+
* the profile lock.
|
|
22
|
+
*/
|
|
23
|
+
export async function closeOnFailure(handle, setup) {
|
|
24
|
+
try {
|
|
25
|
+
return await setup();
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
await handle.close().catch(() => undefined);
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Chrome's profile-lock signatures, as they reach us through Playwright's
|
|
34
|
+
* "Browser output:" dump — `process_singleton_posix.cc` prints the first, the
|
|
35
|
+
* lock-file variants print the others.
|
|
36
|
+
*/
|
|
37
|
+
const PROFILE_LOCK_SIGNATURES = [
|
|
38
|
+
/profile appears to be in use/i,
|
|
39
|
+
/SingletonLock/i,
|
|
40
|
+
/ProcessSingleton/i,
|
|
41
|
+
];
|
|
42
|
+
/**
|
|
43
|
+
* Translate a `create` failure into a loud {@link AdapterError}. An AdapterError
|
|
44
|
+
* passes through as-is — it already names the problem, and double-wrapping would
|
|
45
|
+
* only bury it.
|
|
46
|
+
*/
|
|
47
|
+
export function createFailure(error, ctx) {
|
|
48
|
+
if (error instanceof AdapterError)
|
|
49
|
+
return error;
|
|
50
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
51
|
+
if (ctx.mode === 'attach') {
|
|
52
|
+
return new AdapterError(`browser.create failed: cannot attach to ${ctx.cdpUrl} — ${detail}`);
|
|
53
|
+
}
|
|
54
|
+
if (PROFILE_LOCK_SIGNATURES.some((signature) => signature.test(detail))) {
|
|
55
|
+
return new AdapterError(`browser.create failed: Chrome profile ${ctx.profileDir} is locked by another Chrome — ` +
|
|
56
|
+
'one debug run per project. End the other run (`ui-debugger-mcp stop`) or close that ' +
|
|
57
|
+
`Chrome, then retry — ${detail}`);
|
|
58
|
+
}
|
|
59
|
+
return new AdapterError(`browser.create failed: cannot launch Chrome — ${detail}`);
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=launch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"launch.js","sourceRoot":"","sources":["../../../src/adapters/browser/launch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAO/C;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAI,MAAgB,EAAE,KAAuB;IAC/E,IAAI,CAAC;QACH,OAAO,MAAM,KAAK,EAAE,CAAC;IACvB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC5C,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,uBAAuB,GAAG;IAC9B,+BAA+B;IAC/B,gBAAgB;IAChB,mBAAmB;CACpB,CAAC;AAOF;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc,EAAE,GAAkB;IAC9D,IAAI,KAAK,YAAY,YAAY;QAAE,OAAO,KAAK,CAAC;IAChD,MAAM,MAAM,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAEtE,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC1B,OAAO,IAAI,YAAY,CAAC,2CAA2C,GAAG,CAAC,MAAM,MAAM,MAAM,EAAE,CAAC,CAAC;IAC/F,CAAC;IACD,IAAI,uBAAuB,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;QACxE,OAAO,IAAI,YAAY,CACrB,yCAAyC,GAAG,CAAC,UAAU,iCAAiC;YACtF,sFAAsF;YACtF,wBAAwB,MAAM,EAAE,CACnC,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,YAAY,CAAC,iDAAiD,MAAM,EAAE,CAAC,CAAC;AACrF,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared wall-clock budget guard for adapter waits.
|
|
3
|
+
*
|
|
4
|
+
* A run's `timeout` is a cap measured from `start_debug` receipt, so everything
|
|
5
|
+
* the caller waits on — Chrome launch, the first navigation, an emulator boot —
|
|
6
|
+
* has to fit INSIDE it. The service hands each of those the budget it has left;
|
|
7
|
+
* this is the one place that decides what a budget means: it only ever SHORTENS
|
|
8
|
+
* an adapter's own wait, never extends it past the adapter's default.
|
|
9
|
+
*
|
|
10
|
+
* Two ways a budget could quietly become an INFINITE wait, both guarded here:
|
|
11
|
+
* `Math.min(30_000, NaN)` is `NaN`, and `0` means "no timeout at all" to Playwright.
|
|
12
|
+
* A spent budget floors at 1ms instead — fail fast, never hang (same reasoning as
|
|
13
|
+
* `remainingTimeout` in the browser adapter).
|
|
14
|
+
*/
|
|
15
|
+
/** The adapter's own wait, shortened to `budgetMs` when the caller has less left. */
|
|
16
|
+
export declare function capWait(defaultMs: number, budgetMs?: number): number;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared wall-clock budget guard for adapter waits.
|
|
3
|
+
*
|
|
4
|
+
* A run's `timeout` is a cap measured from `start_debug` receipt, so everything
|
|
5
|
+
* the caller waits on — Chrome launch, the first navigation, an emulator boot —
|
|
6
|
+
* has to fit INSIDE it. The service hands each of those the budget it has left;
|
|
7
|
+
* this is the one place that decides what a budget means: it only ever SHORTENS
|
|
8
|
+
* an adapter's own wait, never extends it past the adapter's default.
|
|
9
|
+
*
|
|
10
|
+
* Two ways a budget could quietly become an INFINITE wait, both guarded here:
|
|
11
|
+
* `Math.min(30_000, NaN)` is `NaN`, and `0` means "no timeout at all" to Playwright.
|
|
12
|
+
* A spent budget floors at 1ms instead — fail fast, never hang (same reasoning as
|
|
13
|
+
* `remainingTimeout` in the browser adapter).
|
|
14
|
+
*/
|
|
15
|
+
import { AdapterError } from '../errors.js';
|
|
16
|
+
/** The adapter's own wait, shortened to `budgetMs` when the caller has less left. */
|
|
17
|
+
export function capWait(defaultMs, budgetMs) {
|
|
18
|
+
if (budgetMs === undefined)
|
|
19
|
+
return defaultMs;
|
|
20
|
+
if (!Number.isFinite(budgetMs) || budgetMs < 0) {
|
|
21
|
+
throw new AdapterError(`\`timeoutMs\` must be a non-negative, finite number of ms (got ${budgetMs})`);
|
|
22
|
+
}
|
|
23
|
+
return Math.max(1, Math.min(defaultMs, budgetMs));
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=budget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"budget.js","sourceRoot":"","sources":["../../src/adapters/budget.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,qFAAqF;AACrF,MAAM,UAAU,OAAO,CAAC,SAAiB,EAAE,QAAiB;IAC1D,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC7C,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,QAAQ,GAAG,CAAC,EAAE,CAAC;QAC/C,MAAM,IAAI,YAAY,CACpB,kEAAkE,QAAQ,GAAG,CAC9E,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC;AACpD,CAAC"}
|
|
@@ -40,6 +40,28 @@ export interface Node {
|
|
|
40
40
|
enabled: boolean;
|
|
41
41
|
/** Stable test hook (`data-testid` on web); absent when the element carries none. */
|
|
42
42
|
testid?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Live contents of a form control (`input`/`textarea`/`select`), absent elsewhere.
|
|
45
|
+
*
|
|
46
|
+
* Distinct from {@link name}, which stays the LABEL so the node remains
|
|
47
|
+
* targetable. Without this the tree cannot answer "what is in this field?" —
|
|
48
|
+
* the accessible name resolves to the label or placeholder, and the `value`
|
|
49
|
+
* attribute never changes as the user types — so a driver verifying its own
|
|
50
|
+
* input had to spend a vision call on it, every time.
|
|
51
|
+
*/
|
|
52
|
+
value?: string;
|
|
53
|
+
/** Live checked state of a checkbox/radio, absent elsewhere. Same rationale as {@link value}. */
|
|
54
|
+
checked?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* The iframe this node lives in (its URL), absent for the main document.
|
|
57
|
+
*
|
|
58
|
+
* Embedded widgets — payment fields, editors, OAuth consent — are a separate
|
|
59
|
+
* document that page-level selectors cannot reach. {@link Bounds} are still
|
|
60
|
+
* page-absolute (the adapter offsets them by the frame's position), so a
|
|
61
|
+
* coordinate click works the same either way; this field is what tells the
|
|
62
|
+
* agent why a selector that "should" match doesn't.
|
|
63
|
+
*/
|
|
64
|
+
frame?: string;
|
|
43
65
|
/**
|
|
44
66
|
* Computed text style (web, text-bearing nodes only) — lets the blind driver
|
|
45
67
|
* catch invisible/low-contrast text structurally, without spending vision.
|
|
@@ -79,8 +101,6 @@ export type Filters = Record<string, FilterValue>;
|
|
|
79
101
|
export interface Query {
|
|
80
102
|
/** `WHERE` / selector — target node(s): CSS/role/text (web), a11y role+name (desktop), resource-id/text (android). */
|
|
81
103
|
query?: string;
|
|
82
|
-
/** `SELECT cols` — which {@link Node} fields to populate for a sparse read; omit for all. */
|
|
83
|
-
fields?: NodeField[];
|
|
84
104
|
/** `WHERE field_op` — structured predicates; see {@link Filters}. Whitelisted per adapter. */
|
|
85
105
|
filters?: Filters;
|
|
86
106
|
/** `LIMIT` — cap how many nodes come back, to keep the tree small. */
|
|
@@ -142,14 +162,58 @@ export interface NetworkEntry {
|
|
|
142
162
|
error?: string;
|
|
143
163
|
/** Capture time, ms since epoch. */
|
|
144
164
|
timestamp: number;
|
|
165
|
+
/**
|
|
166
|
+
* Wall-clock ms from the request leaving the page to its response arriving.
|
|
167
|
+
* Absent when the request never produced a response, or when it was already
|
|
168
|
+
* in flight before capture started.
|
|
169
|
+
*/
|
|
170
|
+
durationMs?: number;
|
|
171
|
+
/**
|
|
172
|
+
* Request payload as sent (`POST`/`PUT`/`PATCH` bodies), truncated to a cap.
|
|
173
|
+
* Captured for API traffic only ({@link BODY_RESOURCE_TYPES}) — a debugger needs
|
|
174
|
+
* to see *what was submitted*, not the bytes of every script and image.
|
|
175
|
+
*/
|
|
176
|
+
requestBody?: string;
|
|
177
|
+
/**
|
|
178
|
+
* Response payload, truncated to a cap. Captured for API traffic only. This is
|
|
179
|
+
* where a `4xx` keeps its actual reason (the validation error, the message), so
|
|
180
|
+
* it is the single most valuable field on a failing exchange.
|
|
181
|
+
*/
|
|
182
|
+
responseBody?: string;
|
|
183
|
+
/** Request headers, sensitive values redacted ({@link NetworkEntry.responseHeaders}). */
|
|
184
|
+
requestHeaders?: Record<string, string>;
|
|
185
|
+
/**
|
|
186
|
+
* Response headers, sensitive values redacted — credential-bearing headers
|
|
187
|
+
* (`authorization`, `cookie`, `set-cookie`, …) keep only a length marker, so the
|
|
188
|
+
* agent can tell a header was *present* without the secret entering its context
|
|
189
|
+
* (and from there, logs, findings, and the caller's transcript).
|
|
190
|
+
*/
|
|
191
|
+
responseHeaders?: Record<string, string>;
|
|
192
|
+
}
|
|
193
|
+
/** One open tab/window of a multi-tab target (web). */
|
|
194
|
+
export interface TabInfo {
|
|
195
|
+
/** Position in the target's tab list — what {@link Adapter.selectTab} takes. */
|
|
196
|
+
index: number;
|
|
197
|
+
/** Current URL of the tab. */
|
|
198
|
+
url: string;
|
|
199
|
+
/** Document title, empty while a fresh tab is still loading. */
|
|
200
|
+
title: string;
|
|
201
|
+
/** Whether this is the tab the adapter currently drives. */
|
|
202
|
+
active: boolean;
|
|
145
203
|
}
|
|
146
204
|
/**
|
|
147
205
|
* One contract, three protocols. The agent loop calls only these methods; each
|
|
148
206
|
* adapter wires them to its real backend (CDP / X11-Wayland / ADB).
|
|
149
207
|
*/
|
|
150
208
|
export interface Adapter {
|
|
151
|
-
/**
|
|
152
|
-
|
|
209
|
+
/**
|
|
210
|
+
* Go to the app: navigate to a URL (web) · launch/focus the window (desktop) · start the activity (android).
|
|
211
|
+
*
|
|
212
|
+
* `timeoutMs` is the caller's REMAINING wall-clock budget for the run: the adapter
|
|
213
|
+
* shortens its own wait to fit inside it and never extends past its own default
|
|
214
|
+
* (see `capWait`). Omit it for the adapter default.
|
|
215
|
+
*/
|
|
216
|
+
open(target: string, timeoutMs?: number): Promise<void>;
|
|
153
217
|
/** Resolve the first node matching {@link Query}; `null` if none match. */
|
|
154
218
|
find(opts: Query): Promise<Node | null>;
|
|
155
219
|
/** Click an element (re-resolving a selector, or using a found {@link Node}). */
|
|
@@ -166,10 +230,22 @@ export interface Adapter {
|
|
|
166
230
|
screenshot(): Promise<Uint8Array>;
|
|
167
231
|
/** Block until {@link WaitOptions} hold (node appears, network idle, …) or time out. */
|
|
168
232
|
waitFor(opts: WaitOptions): Promise<void>;
|
|
169
|
-
/**
|
|
233
|
+
/** Read captured console messages, newest first, narrowed by {@link LogQuery}. Reads are non-destructive. */
|
|
170
234
|
console(opts?: LogQuery): Promise<ConsoleEntry[]>;
|
|
171
|
-
/**
|
|
235
|
+
/** Read captured network exchanges, newest first, narrowed by {@link LogQuery}. Reads are non-destructive. */
|
|
172
236
|
network(opts?: LogQuery): Promise<NetworkEntry[]>;
|
|
237
|
+
/**
|
|
238
|
+
* List the target's open tabs, newest last. OPTIONAL — implemented by targets
|
|
239
|
+
* that have a tab concept (web); absent elsewhere, and the belt says so rather
|
|
240
|
+
* than pretending a single-window target has one tab.
|
|
241
|
+
*/
|
|
242
|
+
tabs?(): Promise<TabInfo[]>;
|
|
243
|
+
/**
|
|
244
|
+
* Drive a different tab from now on: every later read and action targets it,
|
|
245
|
+
* and console/network capture follows. OPTIONAL, paired with {@link tabs}.
|
|
246
|
+
* Throws when the index names no open tab.
|
|
247
|
+
*/
|
|
248
|
+
selectTab?(index: number): Promise<void>;
|
|
173
249
|
/** Release the target: stop a **managed** process; for **attach**, disconnect only — never stop it. */
|
|
174
250
|
close(): Promise<void>;
|
|
175
251
|
}
|