@developerz.ai/ui-debugger-mcp 1.3.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/README.md +11 -0
  2. package/dist/adapters/android/adb.js +3 -1
  3. package/dist/adapters/android/adb.js.map +1 -1
  4. package/dist/adapters/android/android-adapter.js +24 -14
  5. package/dist/adapters/android/android-adapter.js.map +1 -1
  6. package/dist/adapters/android/commands.d.ts +7 -4
  7. package/dist/adapters/android/commands.js +11 -6
  8. package/dist/adapters/android/commands.js.map +1 -1
  9. package/dist/adapters/browser/browser-adapter.d.ts +4 -50
  10. package/dist/adapters/browser/browser-adapter.js +55 -223
  11. package/dist/adapters/browser/browser-adapter.js.map +1 -1
  12. package/dist/adapters/browser/cdp.d.ts +12 -42
  13. package/dist/adapters/browser/cdp.js +122 -261
  14. package/dist/adapters/browser/cdp.js.map +1 -1
  15. package/dist/adapters/browser/geometry.d.ts +97 -0
  16. package/dist/adapters/browser/geometry.js +158 -0
  17. package/dist/adapters/browser/geometry.js.map +1 -0
  18. package/dist/adapters/browser/launch.d.ts +42 -2
  19. package/dist/adapters/browser/launch.js +77 -2
  20. package/dist/adapters/browser/launch.js.map +1 -1
  21. package/dist/adapters/browser/locate.d.ts +44 -0
  22. package/dist/adapters/browser/locate.js +93 -0
  23. package/dist/adapters/browser/locate.js.map +1 -0
  24. package/dist/adapters/browser/log-filters.d.ts +25 -0
  25. package/dist/adapters/browser/log-filters.js +149 -0
  26. package/dist/adapters/browser/log-filters.js.map +1 -0
  27. package/dist/adapters/browser/log-format.d.ts +52 -0
  28. package/dist/adapters/browser/log-format.js +131 -0
  29. package/dist/adapters/browser/log-format.js.map +1 -0
  30. package/dist/adapters/contract.d.ts +22 -2
  31. package/dist/adapters/desktop/atspi.d.ts +7 -0
  32. package/dist/adapters/desktop/atspi.js +3 -0
  33. package/dist/adapters/desktop/atspi.js.map +1 -1
  34. package/dist/adapters/desktop/desktop-adapter.d.ts +8 -1
  35. package/dist/adapters/desktop/desktop-adapter.js +38 -20
  36. package/dist/adapters/desktop/desktop-adapter.js.map +1 -1
  37. package/dist/adapters/desktop/input.d.ts +8 -1
  38. package/dist/adapters/desktop/input.js +12 -3
  39. package/dist/adapters/desktop/input.js.map +1 -1
  40. package/dist/adapters/desktop/proc.d.ts +13 -2
  41. package/dist/adapters/desktop/proc.js +42 -2
  42. package/dist/adapters/desktop/proc.js.map +1 -1
  43. package/dist/adapters/factory.js +5 -1
  44. package/dist/adapters/factory.js.map +1 -1
  45. package/dist/agent/belt/act.d.ts +3 -2
  46. package/dist/agent/belt/act.js +51 -7
  47. package/dist/agent/belt/act.js.map +1 -1
  48. package/dist/agent/belt/look.d.ts +5 -8
  49. package/dist/agent/belt/look.js +47 -8
  50. package/dist/agent/belt/look.js.map +1 -1
  51. package/dist/agent/belt/observe.d.ts +28 -2
  52. package/dist/agent/belt/observe.js +102 -27
  53. package/dist/agent/belt/observe.js.map +1 -1
  54. package/dist/agent/capabilities.d.ts +9 -0
  55. package/dist/agent/capabilities.js +10 -1
  56. package/dist/agent/capabilities.js.map +1 -1
  57. package/dist/agent/loop.d.ts +11 -2
  58. package/dist/agent/loop.js +55 -6
  59. package/dist/agent/loop.js.map +1 -1
  60. package/dist/agent/prompts/android-addendum.d.ts +1 -1
  61. package/dist/agent/prompts/android-addendum.js +20 -5
  62. package/dist/agent/prompts/android-addendum.js.map +1 -1
  63. package/dist/agent/prompts/compose.d.ts +8 -0
  64. package/dist/agent/prompts/compose.js +15 -2
  65. package/dist/agent/prompts/compose.js.map +1 -1
  66. package/dist/agent/prompts/debug-agent.js +12 -0
  67. package/dist/agent/prompts/debug-agent.js.map +1 -1
  68. package/dist/agent/prompts/desktop-addendum.d.ts +1 -1
  69. package/dist/agent/prompts/desktop-addendum.js +18 -5
  70. package/dist/agent/prompts/desktop-addendum.js.map +1 -1
  71. package/dist/agent/prompts/web-addendum.d.ts +1 -1
  72. package/dist/agent/prompts/web-addendum.js +0 -10
  73. package/dist/agent/prompts/web-addendum.js.map +1 -1
  74. package/dist/config/fingerprint.d.ts +6 -0
  75. package/dist/config/fingerprint.js +16 -4
  76. package/dist/config/fingerprint.js.map +1 -1
  77. package/dist/config/schema.d.ts +10 -4
  78. package/dist/config/schema.js +21 -5
  79. package/dist/config/schema.js.map +1 -1
  80. package/dist/index.d.ts +1 -1
  81. package/dist/index.js +1 -1
  82. package/dist/main.js +11 -13
  83. package/dist/main.js.map +1 -1
  84. package/dist/services/debug-service.d.ts +2 -1
  85. package/dist/services/debug-service.js +82 -29
  86. package/dist/services/debug-service.js.map +1 -1
  87. package/dist/services/replay.d.ts +14 -3
  88. package/dist/services/replay.js +57 -10
  89. package/dist/services/replay.js.map +1 -1
  90. package/dist/services/session-builder.js +30 -5
  91. package/dist/services/session-builder.js.map +1 -1
  92. package/dist/services/shutdown.d.ts +37 -0
  93. package/dist/services/shutdown.js +51 -0
  94. package/dist/services/shutdown.js.map +1 -0
  95. package/dist/session/findings-store.d.ts +6 -2
  96. package/dist/session/findings-store.js +39 -6
  97. package/dist/session/findings-store.js.map +1 -1
  98. package/dist/session/session.d.ts +4 -2
  99. package/dist/session/session.js +7 -2
  100. package/dist/session/session.js.map +1 -1
  101. package/dist/session/state-file.d.ts +8 -2
  102. package/dist/session/state-file.js +8 -2
  103. package/dist/session/state-file.js.map +1 -1
  104. package/dist/session/workspace.d.ts +2 -1
  105. package/dist/session/workspace.js +28 -3
  106. package/dist/session/workspace.js.map +1 -1
  107. package/package.json +1 -1
@@ -0,0 +1,158 @@
1
+ /**
2
+ * Coordinates, frames and node shaping for the browser adapter — the pure
3
+ * geometry the page-driving class leans on. Split out of `browser-adapter.ts`
4
+ * to keep that file under the 500-LOC cap (same split `filters.ts` got), no
5
+ * behavior change.
6
+ *
7
+ * Two themes:
8
+ * - **the viewport**: is a point actually on screen, which way does a wheel go;
9
+ * - **frames**: where a child document's viewport sits in PAGE coordinates,
10
+ * and whether a mid-read failure was a frame going away or a real error.
11
+ */
12
+ import { AdapterError } from '../../errors.js';
13
+ /**
14
+ * True when `point` falls outside a non-null `viewport`. Coordinate clicks use
15
+ * viewport-relative bounds (`getBoundingClientRect`), so an off-screen center
16
+ * dispatches a CDP click that lands on nothing — silently. A null viewport means
17
+ * the size could not be established AT ALL (see {@link BrowserAdapter.viewport},
18
+ * which falls back to the page's own `innerWidth/Height` first) → never outside;
19
+ * we can't judge.
20
+ */
21
+ export function isOutsideViewport(point, viewport) {
22
+ if (!viewport)
23
+ return false;
24
+ return point.x < 0 || point.x > viewport.width || point.y < 0 || point.y > viewport.height;
25
+ }
26
+ /**
27
+ * Map a {@link ScrollDirection} + pixel `amount` onto Playwright wheel deltas
28
+ * `[deltaX, deltaY]` (the viewport scrolls toward that edge). Fails loud on an
29
+ * unrecognized direction — the switch is exhaustive over the union, so a bad
30
+ * value can only arrive from an unchecked boundary.
31
+ */
32
+ export function scrollDelta(direction, amount) {
33
+ switch (direction) {
34
+ case 'up':
35
+ return [0, -amount];
36
+ case 'down':
37
+ return [0, amount];
38
+ case 'left':
39
+ return [-amount, 0];
40
+ case 'right':
41
+ return [amount, 0];
42
+ default: {
43
+ const unreachable = direction;
44
+ throw new AdapterError(`unknown scroll direction: ${JSON.stringify(unreachable)}`);
45
+ }
46
+ }
47
+ }
48
+ /**
49
+ * In-page viewport probe — `innerWidth/Height` read off the page itself. Reaches
50
+ * the globals through `globalThis` because the DOM lib is off project-wide; the
51
+ * function is serialized into the page, so it must stay self-contained.
52
+ */
53
+ export const VIEWPORT_PROBE = () => {
54
+ const w = globalThis;
55
+ return { width: w.innerWidth, height: w.innerHeight };
56
+ };
57
+ /** Playwright's wording for "the document I was reading went away mid-read". */
58
+ const FRAME_GONE = /frame was detached|execution context was destroyed|frame got detached|target (page, context or browser )?has been closed|target closed/i;
59
+ /**
60
+ * True when a per-frame read failed because that FRAME vanished (navigation, an
61
+ * ad slot recycling itself), which is one document out of many and not an error.
62
+ *
63
+ * Anything else — an invalid selector above all, the jQuery-ism `div:contains(…)`
64
+ * an LLM emits constantly — is the caller's own mistake and must surface: swallowed,
65
+ * it reads back as `{count: 0}`, i.e. "the element does not exist", while `click()`
66
+ * with the same selector reports the real reason. `detached` is the frame's own
67
+ * live state, checked in addition to the message.
68
+ */
69
+ export function isFrameGone(error, detached) {
70
+ if (detached)
71
+ return true;
72
+ return FRAME_GONE.test(error instanceof Error ? error.message : String(error));
73
+ }
74
+ /**
75
+ * True when a Playwright call failed by RUNNING OUT OF TIME rather than by being
76
+ * wrong — the one failure a cross-frame poll retries instead of surfacing.
77
+ * Playwright brands those as `TimeoutError`.
78
+ */
79
+ export function isTimeout(error) {
80
+ return error instanceof Error && error.name === 'TimeoutError';
81
+ }
82
+ /** Drop the internal `visible` flag — the public contract returns plain {@link Node}s. */
83
+ export function toNode(node) {
84
+ const out = {
85
+ role: node.role,
86
+ name: node.name,
87
+ bounds: node.bounds,
88
+ enabled: node.enabled,
89
+ };
90
+ if (node.testid)
91
+ out.testid = node.testid;
92
+ if (node.style)
93
+ out.style = node.style;
94
+ if (node.frame)
95
+ out.frame = node.frame;
96
+ // Empty string and `false` are real answers here ("the field is empty", "the box
97
+ // is unchecked") — test for presence, never truthiness.
98
+ if (node.value !== undefined)
99
+ out.value = node.value;
100
+ if (node.checked !== undefined)
101
+ out.checked = node.checked;
102
+ return out;
103
+ }
104
+ const FRAME_INSET = (el) => {
105
+ const s = getComputedStyle(el);
106
+ const px = (value) => Number.parseFloat(value) || 0;
107
+ return {
108
+ x: px(s.borderLeftWidth) + px(s.paddingLeft),
109
+ y: px(s.borderTopWidth) + px(s.paddingTop),
110
+ };
111
+ };
112
+ /**
113
+ * Where a frame's viewport sits in page coordinates: `{x:0,y:0}` for the main
114
+ * document, the iframe element's CONTENT origin for a child, `null` when the
115
+ * frame is gone or not rendered (detached, `display:none`) and must be skipped.
116
+ *
117
+ * `boundingBox()` is the iframe's BORDER box, while an in-frame
118
+ * `getBoundingClientRect()` is relative to its content origin — so without the
119
+ * border+padding inset every node inside an iframe carrying the UA's default
120
+ * `2px inset` border is off by exactly that much.
121
+ */
122
+ export async function frameOffset(frame) {
123
+ if (frame.parentFrame() === null)
124
+ return { x: 0, y: 0 };
125
+ try {
126
+ const element = await frame.frameElement();
127
+ const box = await element.boundingBox();
128
+ if (!box)
129
+ return null;
130
+ const inset = await element.evaluate(FRAME_INSET);
131
+ return { x: box.x + inset.x, y: box.y + inset.y };
132
+ }
133
+ catch {
134
+ return null; // detached between listing and reading
135
+ }
136
+ }
137
+ /**
138
+ * Translate a node read inside a frame into page coordinates and stamp which
139
+ * frame it came from.
140
+ *
141
+ * Bounds arrive relative to the frame's own viewport; clicks dispatch against
142
+ * the page. Without the shift, every click on embedded content would land at the
143
+ * wrong place on the page — silently, since the coordinates stay plausible.
144
+ */
145
+ export function placeInPage(node, offset, frame) {
146
+ if (frame.parentFrame() === null)
147
+ return node;
148
+ return {
149
+ ...node,
150
+ bounds: {
151
+ ...node.bounds,
152
+ x: node.bounds.x + offset.x,
153
+ y: node.bounds.y + offset.y,
154
+ },
155
+ frame: frame.url(),
156
+ };
157
+ }
158
+ //# sourceMappingURL=geometry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geometry.js","sourceRoot":"","sources":["../../../src/adapters/browser/geometry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAI/C;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAC/B,KAA+B,EAC/B,QAAkD;IAElD,IAAI,CAAC,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5B,OAAO,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,CAAC,GAAG,QAAQ,CAAC,KAAK,IAAI,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC;AAC7F,CAAC;AAED;;;;;GAKG;AACH,MAAM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IAC5C,IAAI,KAAK,CAAC,WAAW,EAAE,KAAK,IAAI;QAAE,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IACxD,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,YAAY,EAAE,CAAC;QAC3C,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,WAAW,EAAE,CAAC;QACxC,IAAI,CAAC,GAAG;YAAE,OAAO,IAAI,CAAC;QACtB,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;QAClD,OAAO,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC;IACpD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC,CAAC,uCAAuC;IACtD,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CACzB,IAAa,EACb,MAAgC,EAChC,KAAY;IAEZ,IAAI,KAAK,CAAC,WAAW,EAAE,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAC9C,OAAO;QACL,GAAG,IAAI;QACP,MAAM,EAAE;YACN,GAAG,IAAI,CAAC,MAAM;YACd,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC;YAC3B,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC;SAC5B;QACD,KAAK,EAAE,KAAK,CAAC,GAAG,EAAE;KACnB,CAAC;AACJ,CAAC"}
@@ -1,7 +1,10 @@
1
1
  /**
2
- * Browser lifecycle guards — the failure paths of {@link BrowserAdapter.create}.
2
+ * Getting Chrome open and pointed at the app — which binary, which URL, and the
3
+ * failure paths of {@link BrowserAdapter.create}.
3
4
  *
4
- * Two rules, both about not poisoning the NEXT run:
5
+ * Resolution first (binary, navigation target, login-bypass param, the default
6
+ * waits the run budget may only shorten), then two rules about not poisoning the
7
+ * NEXT run:
5
8
  * - **No zombie Chrome.** Anything that throws after the browser is already up
6
9
  * must close it before rethrowing. A leaked persistent context keeps holding
7
10
  * the per-project profile lock, so every later launch dies on it.
@@ -11,7 +14,44 @@
11
14
  *
12
15
  * Lives beside the adapter rather than inside it: same reason `query.ts`/`cdp.ts` do.
13
16
  */
17
+ import type { WebTarget } from '../../config/schema.js';
14
18
  import { AdapterError } from '../../errors.js';
19
+ /**
20
+ * Playwright's own defaults for launching/connecting and for a navigation, restated
21
+ * so the run budget can only SHORTEN them (`capWait`). Left implicit, these two sit
22
+ * OUTSIDE the caller's cap and a `start_debug` with `timeout: 10` could still burn a
23
+ * minute before the driver takes its first step.
24
+ */
25
+ export declare const LAUNCH_TIMEOUT_MS = 30000;
26
+ export declare const NAV_TIMEOUT_MS = 30000;
27
+ /**
28
+ * Pick the Chromium binary for a managed launch. Order:
29
+ * 1. explicit `executablePath` from config
30
+ * 2. the Playwright-managed Chromium, if it's installed (`npx playwright install chromium`)
31
+ * 3. fall back to the system Google Chrome channel
32
+ * Without (2) the adapter failed on hosts that have the managed Chromium but no
33
+ * system Chrome — the common dev setup. `detect` is injected so the ordering is
34
+ * unit-testable without a real browser install.
35
+ */
36
+ export declare function resolveLaunchBinary(config: WebTarget, detect?: () => string | null): {
37
+ executablePath: string;
38
+ } | {
39
+ channel: string;
40
+ };
41
+ /**
42
+ * Resolve a navigate target against the configured base URL. Drivers often pass
43
+ * a relative path (`/`, `/login`) — `page.goto` rejects those as "invalid URL",
44
+ * so anchor them to `base`. Absolute targets pass through unchanged.
45
+ */
46
+ export declare function resolveTargetUrl(target: string, base?: string): string;
47
+ /**
48
+ * Append the login-bypass query param (`?<param>=true`) when `debugLogin` is configured.
49
+ * A relative `target` (no config `url` base to anchor it) can't carry a query param —
50
+ * fail loud with an {@link AdapterError} instead of leaking a raw `TypeError: Invalid URL`.
51
+ */
52
+ export declare function appendDebugLogin(target: string, debugLogin?: {
53
+ param: string;
54
+ }): string;
15
55
  /** A Playwright handle opened by a lifecycle: the context (managed) or the browser (attach). */
16
56
  export interface Closable {
17
57
  close(): Promise<void>;
@@ -1,7 +1,10 @@
1
1
  /**
2
- * Browser lifecycle guards — the failure paths of {@link BrowserAdapter.create}.
2
+ * Getting Chrome open and pointed at the app — which binary, which URL, and the
3
+ * failure paths of {@link BrowserAdapter.create}.
3
4
  *
4
- * Two rules, both about not poisoning the NEXT run:
5
+ * Resolution first (binary, navigation target, login-bypass param, the default
6
+ * waits the run budget may only shorten), then two rules about not poisoning the
7
+ * NEXT run:
5
8
  * - **No zombie Chrome.** Anything that throws after the browser is already up
6
9
  * must close it before rethrowing. A leaked persistent context keeps holding
7
10
  * the per-project profile lock, so every later launch dies on it.
@@ -11,7 +14,79 @@
11
14
  *
12
15
  * Lives beside the adapter rather than inside it: same reason `query.ts`/`cdp.ts` do.
13
16
  */
17
+ import { existsSync } from 'node:fs';
18
+ import { URL } from 'node:url';
19
+ import { chromium } from 'playwright-core';
14
20
  import { AdapterError } from '../../errors.js';
21
+ // --- What to launch, and where to point it ----------------------------------
22
+ /** System Chrome channel used as the last resort when no binary can be resolved. */
23
+ const DEFAULT_CHANNEL = 'chrome';
24
+ /**
25
+ * Playwright's own defaults for launching/connecting and for a navigation, restated
26
+ * so the run budget can only SHORTEN them (`capWait`). Left implicit, these two sit
27
+ * OUTSIDE the caller's cap and a `start_debug` with `timeout: 10` could still burn a
28
+ * minute before the driver takes its first step.
29
+ */
30
+ export const LAUNCH_TIMEOUT_MS = 30_000;
31
+ export const NAV_TIMEOUT_MS = 30_000;
32
+ /** Detect the Playwright-managed Chromium binary; null if it isn't installed. */
33
+ function detectManagedChromium() {
34
+ try {
35
+ const p = chromium.executablePath();
36
+ return p && existsSync(p) ? p : null;
37
+ }
38
+ catch {
39
+ return null; // Playwright browser not installed
40
+ }
41
+ }
42
+ /**
43
+ * Pick the Chromium binary for a managed launch. Order:
44
+ * 1. explicit `executablePath` from config
45
+ * 2. the Playwright-managed Chromium, if it's installed (`npx playwright install chromium`)
46
+ * 3. fall back to the system Google Chrome channel
47
+ * Without (2) the adapter failed on hosts that have the managed Chromium but no
48
+ * system Chrome — the common dev setup. `detect` is injected so the ordering is
49
+ * unit-testable without a real browser install.
50
+ */
51
+ export function resolveLaunchBinary(config, detect = detectManagedChromium) {
52
+ if (config.executablePath)
53
+ return { executablePath: config.executablePath };
54
+ const managed = detect();
55
+ if (managed)
56
+ return { executablePath: managed };
57
+ return { channel: DEFAULT_CHANNEL };
58
+ }
59
+ /**
60
+ * Resolve a navigate target against the configured base URL. Drivers often pass
61
+ * a relative path (`/`, `/login`) — `page.goto` rejects those as "invalid URL",
62
+ * so anchor them to `base`. Absolute targets pass through unchanged.
63
+ */
64
+ export function resolveTargetUrl(target, base) {
65
+ try {
66
+ return new URL(target, base).toString();
67
+ }
68
+ catch {
69
+ return target; // relative target with no usable base — let `goto` surface a clear error
70
+ }
71
+ }
72
+ /**
73
+ * Append the login-bypass query param (`?<param>=true`) when `debugLogin` is configured.
74
+ * A relative `target` (no config `url` base to anchor it) can't carry a query param —
75
+ * fail loud with an {@link AdapterError} instead of leaking a raw `TypeError: Invalid URL`.
76
+ */
77
+ export function appendDebugLogin(target, debugLogin) {
78
+ if (!debugLogin)
79
+ return target;
80
+ let url;
81
+ try {
82
+ url = new URL(target);
83
+ }
84
+ catch {
85
+ throw new AdapterError(`cannot append debug-login param to relative target ${JSON.stringify(target)} — set the web target's \`url\` in .ui-debugger-mcp.json so it resolves to an absolute URL`);
86
+ }
87
+ url.searchParams.set(debugLogin.param, 'true');
88
+ return url.toString();
89
+ }
15
90
  /**
16
91
  * Run post-connect setup, closing `handle` if it throws. On success the value is
17
92
  * returned untouched and the handle stays open — the caller owns it from then on.
@@ -1 +1 @@
1
- {"version":3,"file":"launch.js","sourceRoot":"","sources":["../../../src/adapters/browser/launch.ts"],"names":[],"mappings":"A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C,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,44 @@
1
+ /**
2
+ * Resolving a selector against a page that has MORE THAN ONE document.
3
+ *
4
+ * `page.locator()` never crosses an iframe boundary, but `readState` does — it
5
+ * reads every frame and tags what it found with `frame`. A driver that then acts
6
+ * on (or waits for, or scopes to) such a target would otherwise be told it does
7
+ * not exist. These three fall through the frames instead:
8
+ * - {@link locateAcrossFrames} — a locator from whichever frame holds it;
9
+ * - {@link waitAcrossFrames} — a wait that any frame can satisfy;
10
+ * - {@link regionAcrossFrames} — a `within` scope as a page-coordinate rect.
11
+ *
12
+ * Split out of `browser-adapter.ts` to keep that file under the 500-LOC cap.
13
+ */
14
+ import type { Locator, Page } from 'playwright-core';
15
+ import type { Bounds, NodeRef } from '../contract.js';
16
+ /**
17
+ * A locator for `selector` in whichever frame actually contains it — the main
18
+ * document first, then every child frame.
19
+ *
20
+ * Falling back through the frames keeps `act` working on a target the agent can
21
+ * plainly see in the tree.
22
+ */
23
+ export declare function locateAcrossFrames(page: Page, selector: string): Promise<Locator>;
24
+ /**
25
+ * Wait until `query` is visible in ANY frame — whichever shows it first wins.
26
+ *
27
+ * Locating first is not enough here: `waitFor` exists for things that do not
28
+ * exist YET, in any frame.
29
+ *
30
+ * Polls frame by frame in SLICES rather than starting one full-length wait per
31
+ * frame in parallel. A Playwright wait cannot be cancelled, so the parallel form
32
+ * leaves a poller hammering the page for every frame that never matches — long
33
+ * after the wait it belonged to returned. Re-reading `frames()` each pass also
34
+ * picks up frames that appear mid-wait.
35
+ */
36
+ export declare function waitAcrossFrames(page: Page, query: string, timeout?: number): Promise<void>;
37
+ /**
38
+ * Resolve a `within` scope to a rectangle in PAGE coordinates — {@link Node}
39
+ * bounds as given, a selector via {@link locateAcrossFrames} so a scrollable
40
+ * region (or a read scope) inside an iframe resolves like any other target.
41
+ * Playwright's `boundingBox()` is main-frame-relative even for an in-frame
42
+ * element, so a viewport guard downstream stays correct.
43
+ */
44
+ export declare function regionAcrossFrames(page: Page, within: NodeRef): Promise<Bounds>;
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Resolving a selector against a page that has MORE THAN ONE document.
3
+ *
4
+ * `page.locator()` never crosses an iframe boundary, but `readState` does — it
5
+ * reads every frame and tags what it found with `frame`. A driver that then acts
6
+ * on (or waits for, or scopes to) such a target would otherwise be told it does
7
+ * not exist. These three fall through the frames instead:
8
+ * - {@link locateAcrossFrames} — a locator from whichever frame holds it;
9
+ * - {@link waitAcrossFrames} — a wait that any frame can satisfy;
10
+ * - {@link regionAcrossFrames} — a `within` scope as a page-coordinate rect.
11
+ *
12
+ * Split out of `browser-adapter.ts` to keep that file under the 500-LOC cap.
13
+ */
14
+ import { AdapterError } from '../../errors.js';
15
+ import { isFrameGone, isTimeout } from './geometry.js';
16
+ import { normalizeQuery } from './query.js';
17
+ /** Playwright's own `waitFor` default, restated so the cross-frame poll has a budget. */
18
+ const WAIT_TIMEOUT_MS = 30_000;
19
+ /** One frame's turn in that poll — short, so no frame's wait outlives the call. */
20
+ const WAIT_SLICE_MS = 250;
21
+ /**
22
+ * A locator for `selector` in whichever frame actually contains it — the main
23
+ * document first, then every child frame.
24
+ *
25
+ * Falling back through the frames keeps `act` working on a target the agent can
26
+ * plainly see in the tree.
27
+ */
28
+ export async function locateAcrossFrames(page, selector) {
29
+ const normalized = normalizeQuery(selector);
30
+ for (const frame of page.frames()) {
31
+ const locator = frame.locator(normalized).first();
32
+ try {
33
+ if ((await locator.count()) > 0)
34
+ return locator;
35
+ }
36
+ catch {
37
+ // Detached frame — try the next one.
38
+ }
39
+ }
40
+ // Nothing matched anywhere: hand back the main-frame locator so the caller's
41
+ // own action reports the miss with Playwright's message, as it always did.
42
+ return page.locator(normalized).first();
43
+ }
44
+ /**
45
+ * Wait until `query` is visible in ANY frame — whichever shows it first wins.
46
+ *
47
+ * Locating first is not enough here: `waitFor` exists for things that do not
48
+ * exist YET, in any frame.
49
+ *
50
+ * Polls frame by frame in SLICES rather than starting one full-length wait per
51
+ * frame in parallel. A Playwright wait cannot be cancelled, so the parallel form
52
+ * leaves a poller hammering the page for every frame that never matches — long
53
+ * after the wait it belonged to returned. Re-reading `frames()` each pass also
54
+ * picks up frames that appear mid-wait.
55
+ */
56
+ export async function waitAcrossFrames(page, query, timeout) {
57
+ const selector = normalizeQuery(query);
58
+ const budget = timeout ?? WAIT_TIMEOUT_MS;
59
+ const deadline = Date.now() + budget;
60
+ do {
61
+ for (const frame of page.frames()) {
62
+ const slice = Math.min(WAIT_SLICE_MS, Math.max(1, deadline - Date.now()));
63
+ try {
64
+ await frame.locator(selector).first().waitFor({ state: 'visible', timeout: slice });
65
+ return;
66
+ }
67
+ catch (error) {
68
+ // Not-here-yet (a slice timing out) and a frame that vanished are both
69
+ // "try the next one"; a bad selector is the caller's mistake — fail loud.
70
+ if (!isTimeout(error) && !isFrameGone(error, frame.isDetached()))
71
+ throw error;
72
+ }
73
+ }
74
+ } while (Date.now() < deadline);
75
+ throw new AdapterError(`waitFor: ${JSON.stringify(query)} never became visible in any frame within ${budget}ms`);
76
+ }
77
+ /**
78
+ * Resolve a `within` scope to a rectangle in PAGE coordinates — {@link Node}
79
+ * bounds as given, a selector via {@link locateAcrossFrames} so a scrollable
80
+ * region (or a read scope) inside an iframe resolves like any other target.
81
+ * Playwright's `boundingBox()` is main-frame-relative even for an in-frame
82
+ * element, so a viewport guard downstream stays correct.
83
+ */
84
+ export async function regionAcrossFrames(page, within) {
85
+ if (typeof within !== 'string')
86
+ return within.bounds;
87
+ const box = await (await locateAcrossFrames(page, within)).boundingBox();
88
+ if (!box) {
89
+ throw new AdapterError(`\`within\` target not found or not visible: ${within}`);
90
+ }
91
+ return box;
92
+ }
93
+ //# sourceMappingURL=locate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locate.js","sourceRoot":"","sources":["../../../src/adapters/browser/locate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,yFAAyF;AACzF,MAAM,eAAe,GAAG,MAAM,CAAC;AAE/B,mFAAmF;AACnF,MAAM,aAAa,GAAG,GAAG,CAAC;AAE1B;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,IAAU,EAAE,QAAgB;IACnE,MAAM,UAAU,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;IAC5C,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;QAClC,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,CAAC;QAClD,IAAI,CAAC;YACH,IAAI,CAAC,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC;gBAAE,OAAO,OAAO,CAAC;QAClD,CAAC;QAAC,MAAM,CAAC;YACP,qCAAqC;QACvC,CAAC;IACH,CAAC;IACD,6EAA6E;IAC7E,2EAA2E;IAC3E,OAAO,IAAI,CAAC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AAe;IAClE,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC,MAAM,CAAC;IACrD,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,kBAAkB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;IACzE,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,YAAY,CAAC,+CAA+C,MAAM,EAAE,CAAC,CAAC;IAClF,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Whitelisted `filters` for the console + network log channels. Split out of
3
+ * `cdp.ts` to keep that file under the 500-LOC cap — no behavior change (same
4
+ * split `filters.ts` got out of `browser-adapter.ts`).
5
+ *
6
+ * Filters fail loud: an unknown key or a wrong value type throws
7
+ * {@link AdapterError}, never a silent ignore.
8
+ */
9
+ import type { ConsoleEntry, Filters, NetworkEntry } from '../contract.js';
10
+ /** Whitelisted `filters` keys for the console channel — anything else is rejected. */
11
+ export declare const CONSOLE_FILTER_KEYS: readonly ["level_eq", "level_in", "text_contains"];
12
+ /** Whitelisted `filters` keys for the network channel — anything else is rejected. */
13
+ export declare const NETWORK_FILTER_KEYS: readonly ["status_eq", "status_gte", "status_lt", "ok_eq", "failed_eq", "method_eq", "resource_in", "url_contains", "duration_gte", "body_contains"];
14
+ /**
15
+ * Narrow console entries by the whitelisted `filters` keys
16
+ * ({@link CONSOLE_FILTER_KEYS}). Throws {@link AdapterError} on an unknown key
17
+ * (no silent injection surface) or a wrong value type.
18
+ */
19
+ export declare function filterConsole(entries: ConsoleEntry[], filters?: Filters): ConsoleEntry[];
20
+ /**
21
+ * Narrow network entries by the whitelisted `filters` keys
22
+ * ({@link NETWORK_FILTER_KEYS}). Throws {@link AdapterError} on an unknown key or
23
+ * a wrong value type.
24
+ */
25
+ export declare function filterNetwork(entries: NetworkEntry[], filters?: Filters): NetworkEntry[];
@@ -0,0 +1,149 @@
1
+ /**
2
+ * Whitelisted `filters` for the console + network log channels. Split out of
3
+ * `cdp.ts` to keep that file under the 500-LOC cap — no behavior change (same
4
+ * split `filters.ts` got out of `browser-adapter.ts`).
5
+ *
6
+ * Filters fail loud: an unknown key or a wrong value type throws
7
+ * {@link AdapterError}, never a silent ignore.
8
+ */
9
+ import { AdapterError } from '../../errors.js';
10
+ /** Whitelisted `filters` keys for the console channel — anything else is rejected. */
11
+ export const CONSOLE_FILTER_KEYS = ['level_eq', 'level_in', 'text_contains'];
12
+ /** Whitelisted `filters` keys for the network channel — anything else is rejected. */
13
+ export const NETWORK_FILTER_KEYS = [
14
+ 'status_eq',
15
+ 'status_gte',
16
+ 'status_lt',
17
+ 'ok_eq',
18
+ 'failed_eq',
19
+ 'method_eq',
20
+ 'resource_in',
21
+ 'url_contains',
22
+ 'duration_gte',
23
+ 'body_contains',
24
+ ];
25
+ // --- Filter value type-guards (fail loud, never coerce) ---------------------
26
+ function expectBoolean(key, value) {
27
+ if (typeof value !== 'boolean')
28
+ throw new AdapterError(`filter \`${key}\` expects a boolean`);
29
+ return value;
30
+ }
31
+ function expectNumber(key, value) {
32
+ if (typeof value !== 'number')
33
+ throw new AdapterError(`filter \`${key}\` expects a number`);
34
+ return value;
35
+ }
36
+ function expectString(key, value) {
37
+ if (typeof value !== 'string')
38
+ throw new AdapterError(`filter \`${key}\` expects a string`);
39
+ return value;
40
+ }
41
+ function expectStringArray(key, value) {
42
+ if (!Array.isArray(value) || value.some((v) => typeof v !== 'string')) {
43
+ throw new AdapterError(`filter \`${key}\` expects a string[]`);
44
+ }
45
+ return value;
46
+ }
47
+ // --- Filtering (whitelisted, per-channel) -----------------------------------
48
+ /**
49
+ * Narrow console entries by the whitelisted `filters` keys
50
+ * ({@link CONSOLE_FILTER_KEYS}). Throws {@link AdapterError} on an unknown key
51
+ * (no silent injection surface) or a wrong value type.
52
+ */
53
+ export function filterConsole(entries, filters) {
54
+ if (!filters)
55
+ return entries;
56
+ let out = entries;
57
+ for (const [key, value] of Object.entries(filters)) {
58
+ switch (key) {
59
+ case 'level_eq': {
60
+ const want = expectString(key, value);
61
+ out = out.filter((e) => e.level === want);
62
+ break;
63
+ }
64
+ case 'level_in': {
65
+ const want = expectStringArray(key, value);
66
+ out = out.filter((e) => want.includes(e.level));
67
+ break;
68
+ }
69
+ case 'text_contains': {
70
+ const needle = expectString(key, value).toLowerCase();
71
+ out = out.filter((e) => e.text.toLowerCase().includes(needle));
72
+ break;
73
+ }
74
+ default:
75
+ throw new AdapterError(`unknown console filter \`${key}\` (allowed: ${CONSOLE_FILTER_KEYS.join(', ')})`);
76
+ }
77
+ }
78
+ return out;
79
+ }
80
+ /**
81
+ * Narrow network entries by the whitelisted `filters` keys
82
+ * ({@link NETWORK_FILTER_KEYS}). Throws {@link AdapterError} on an unknown key or
83
+ * a wrong value type.
84
+ */
85
+ export function filterNetwork(entries, filters) {
86
+ if (!filters)
87
+ return entries;
88
+ let out = entries;
89
+ for (const [key, value] of Object.entries(filters)) {
90
+ switch (key) {
91
+ case 'status_eq': {
92
+ const want = expectNumber(key, value);
93
+ out = out.filter((e) => e.status === want);
94
+ break;
95
+ }
96
+ case 'status_gte': {
97
+ const want = expectNumber(key, value);
98
+ out = out.filter((e) => e.status >= want);
99
+ break;
100
+ }
101
+ case 'status_lt': {
102
+ const want = expectNumber(key, value);
103
+ out = out.filter((e) => e.status < want);
104
+ break;
105
+ }
106
+ case 'ok_eq': {
107
+ const want = expectBoolean(key, value);
108
+ out = out.filter((e) => e.ok === want);
109
+ break;
110
+ }
111
+ case 'failed_eq': {
112
+ const want = expectBoolean(key, value);
113
+ out = out.filter((e) => (e.error !== undefined) === want);
114
+ break;
115
+ }
116
+ case 'method_eq': {
117
+ const want = expectString(key, value).toUpperCase();
118
+ out = out.filter((e) => e.method.toUpperCase() === want);
119
+ break;
120
+ }
121
+ case 'resource_in': {
122
+ const want = expectStringArray(key, value);
123
+ out = out.filter((e) => e.resourceType !== undefined && want.includes(e.resourceType));
124
+ break;
125
+ }
126
+ case 'url_contains': {
127
+ const needle = expectString(key, value).toLowerCase();
128
+ out = out.filter((e) => e.url.toLowerCase().includes(needle));
129
+ break;
130
+ }
131
+ case 'duration_gte': {
132
+ const want = expectNumber(key, value);
133
+ // A request with no timing (never answered, or in flight before capture)
134
+ // is not "slower than N" — excluded rather than counted as 0.
135
+ out = out.filter((e) => e.durationMs !== undefined && e.durationMs >= want);
136
+ break;
137
+ }
138
+ case 'body_contains': {
139
+ const needle = expectString(key, value).toLowerCase();
140
+ out = out.filter((e) => `${e.requestBody ?? ''}\n${e.responseBody ?? ''}`.toLowerCase().includes(needle));
141
+ break;
142
+ }
143
+ default:
144
+ throw new AdapterError(`unknown network filter \`${key}\` (allowed: ${NETWORK_FILTER_KEYS.join(', ')})`);
145
+ }
146
+ }
147
+ return out;
148
+ }
149
+ //# sourceMappingURL=log-filters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log-filters.js","sourceRoot":"","sources":["../../../src/adapters/browser/log-filters.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAG/C,sFAAsF;AACtF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,UAAU,EAAE,UAAU,EAAE,eAAe,CAAU,CAAC;AAEtF,sFAAsF;AACtF,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,WAAW;IACX,YAAY;IACZ,WAAW;IACX,OAAO;IACP,WAAW;IACX,WAAW;IACX,aAAa;IACb,cAAc;IACd,cAAc;IACd,eAAe;CACP,CAAC;AAEX,+EAA+E;AAE/E,SAAS,aAAa,CAAC,GAAW,EAAE,KAAkB;IACpD,IAAI,OAAO,KAAK,KAAK,SAAS;QAAE,MAAM,IAAI,YAAY,CAAC,YAAY,GAAG,sBAAsB,CAAC,CAAC;IAC9F,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,YAAY,CAAC,GAAW,EAAE,KAAkB;IACnD,IAAI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