@mario.andreschak/mcp-browser 3.42.1 → 3.44.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.
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The in-page audio tap.
3
+ *
4
+ * Chromium renders a page's audio into a device sink Node cannot reach, so the
5
+ * only portable way to hear what an isolated session is playing is to intercept
6
+ * the Web Audio graph inside the page and ship the samples out ourselves. This
7
+ * is the same shape the MCP audio studio app uses in reverse: audio is always
8
+ * produced by Web Audio in the *viewer's* browser, never streamed as encoded
9
+ * media, which is why it plays without codec or CSP trouble.
10
+ *
11
+ * Two sources have to be covered:
12
+ * 1. pages that build their own AudioContext — their `destination` is replaced
13
+ * by a tap node, so their whole graph flows through us;
14
+ * 2. plain `<audio>`/`<video>` elements — each is routed into a shared tap
15
+ * context the first time it plays.
16
+ *
17
+ * The script must run in the page's MAIN world, which is why the gateway
18
+ * injects it over CDP: Patchright evaluates Playwright scripts in an isolated
19
+ * world where patching `window` would have no effect. `--mute-audio` only
20
+ * silences the device sink, so the graph still carries real samples and the
21
+ * host machine still stays quiet.
22
+ */
23
+ export declare function audioTapSource(binding: string, initiallyMuted?: boolean): string;
@@ -0,0 +1,147 @@
1
+ /**
2
+ * The in-page audio tap.
3
+ *
4
+ * Chromium renders a page's audio into a device sink Node cannot reach, so the
5
+ * only portable way to hear what an isolated session is playing is to intercept
6
+ * the Web Audio graph inside the page and ship the samples out ourselves. This
7
+ * is the same shape the MCP audio studio app uses in reverse: audio is always
8
+ * produced by Web Audio in the *viewer's* browser, never streamed as encoded
9
+ * media, which is why it plays without codec or CSP trouble.
10
+ *
11
+ * Two sources have to be covered:
12
+ * 1. pages that build their own AudioContext — their `destination` is replaced
13
+ * by a tap node, so their whole graph flows through us;
14
+ * 2. plain `<audio>`/`<video>` elements — each is routed into a shared tap
15
+ * context the first time it plays.
16
+ *
17
+ * The script must run in the page's MAIN world, which is why the gateway
18
+ * injects it over CDP: Patchright evaluates Playwright scripts in an isolated
19
+ * world where patching `window` would have no effect. `--mute-audio` only
20
+ * silences the device sink, so the graph still carries real samples and the
21
+ * host machine still stays quiet.
22
+ */
23
+ export function audioTapSource(binding, initiallyMuted = false) {
24
+ const muted = initiallyMuted ? 'true' : 'false';
25
+ return `(function(){
26
+ if (window.__flujoAudioTap) { window.__flujoAudioMuted = ${muted}; return; }
27
+ var NativeCtx = window.AudioContext || window.webkitAudioContext;
28
+ if (!NativeCtx) return;
29
+ window.__flujoAudioTap = true;
30
+ window.__flujoAudioMuted = ${muted};
31
+ var CHUNK = 4096;
32
+ var SILENCE = 1 / 32768;
33
+
34
+ function encode(bytes){
35
+ var out = "", step = 0x8000;
36
+ for (var i = 0; i < bytes.length; i += step) {
37
+ out += String.fromCharCode.apply(null, bytes.subarray(i, i + step));
38
+ }
39
+ return btoa(out);
40
+ }
41
+
42
+ /** Insert a silent recorder between a context's graph and its real output. */
43
+ function tap(ctx, output){
44
+ var input = ctx.createGain();
45
+ var processor = ctx.createScriptProcessor(CHUNK, 2, 2);
46
+ processor.onaudioprocess = function(event){
47
+ var send = window.${binding};
48
+ if (window.__flujoAudioMuted || typeof send !== "function") return;
49
+ var buffer = event.inputBuffer;
50
+ var frames = buffer.length;
51
+ var left = buffer.getChannelData(0);
52
+ var right = buffer.numberOfChannels > 1 ? buffer.getChannelData(1) : left;
53
+ var pcm = new Int16Array(frames * 2);
54
+ var silent = true;
55
+ for (var i = 0; i < frames; i++) {
56
+ var a = left[i], b = right[i];
57
+ if (a > 1) a = 1; else if (a < -1) a = -1;
58
+ if (b > 1) b = 1; else if (b < -1) b = -1;
59
+ if (silent && (a > SILENCE || a < -SILENCE || b > SILENCE || b < -SILENCE)) silent = false;
60
+ pcm[i * 2] = a * 32767;
61
+ pcm[i * 2 + 1] = b * 32767;
62
+ }
63
+ // Digital silence is the common case on a normal page; never spend
64
+ // bandwidth or CDP round trips on it.
65
+ if (silent) return;
66
+ try {
67
+ send(JSON.stringify({ rate: ctx.sampleRate, pcm: encode(new Uint8Array(pcm.buffer)) }));
68
+ } catch (error) {
69
+ window.__flujoAudioMuted = true;
70
+ }
71
+ };
72
+ input.connect(processor);
73
+ // A ScriptProcessor only runs while it is reachable from the destination.
74
+ // Its own output stays silent because onaudioprocess never writes one.
75
+ processor.connect(output);
76
+ return input;
77
+ }
78
+
79
+ // 1) Pages with their own AudioContext.
80
+ function patch(Ctor){
81
+ if (typeof Ctor !== "function") return Ctor;
82
+ function Patched(){
83
+ var ctx = new (Function.prototype.bind.apply(Ctor, [null].concat([].slice.call(arguments))))();
84
+ try {
85
+ var input = tap(ctx, ctx.destination);
86
+ input.maxChannelCount = ctx.destination.maxChannelCount;
87
+ Object.defineProperty(ctx, "destination", {
88
+ configurable: true,
89
+ get: function(){ return input; }
90
+ });
91
+ } catch (error) { /* an untappable context still plays normally */ }
92
+ return ctx;
93
+ }
94
+ Patched.prototype = Ctor.prototype;
95
+ return Patched;
96
+ }
97
+ try {
98
+ if (window.AudioContext) window.AudioContext = patch(window.AudioContext);
99
+ if (window.webkitAudioContext) window.webkitAudioContext = patch(window.webkitAudioContext);
100
+ } catch (error) { /* frozen globals: media elements below still work */ }
101
+
102
+ // 2) Plain media elements, routed into one shared context on first play.
103
+ var mediaCtx, mediaTap, attached = new WeakSet();
104
+ function attach(element){
105
+ if (attached.has(element)) return;
106
+ try {
107
+ if (!mediaCtx) {
108
+ mediaCtx = new NativeCtx();
109
+ mediaTap = tap(mediaCtx, mediaCtx.destination);
110
+ }
111
+ attached.add(element);
112
+ mediaCtx.createMediaElementSource(element).connect(mediaTap);
113
+ if (mediaCtx.state === "suspended") mediaCtx.resume();
114
+ } catch (error) {
115
+ // Cross-origin media without CORS headers taints the graph; leave the
116
+ // element alone so at least the picture keeps playing.
117
+ }
118
+ }
119
+ document.addEventListener("play", function(event){
120
+ var target = event.target;
121
+ if (target && (target.tagName === "AUDIO" || target.tagName === "VIDEO")) attach(target);
122
+ }, true);
123
+
124
+ // Installing the tap after a session was opened must still recover media
125
+ // whose play event already fired. The pre-navigation install is the normal
126
+ // path; this scan is the fallback for reused sessions and dynamically added
127
+ // elements that began playing before they entered the document.
128
+ function attachPlaying(root){
129
+ if (!root) return;
130
+ if ((root.tagName === "AUDIO" || root.tagName === "VIDEO") && !root.paused && !root.ended) attach(root);
131
+ if (typeof root.querySelectorAll !== "function") return;
132
+ var media = root.querySelectorAll("audio,video");
133
+ for (var i = 0; i < media.length; i++) {
134
+ if (!media[i].paused && !media[i].ended) attach(media[i]);
135
+ }
136
+ }
137
+ attachPlaying(document);
138
+ if (window.MutationObserver) {
139
+ new MutationObserver(function(records){
140
+ for (var i = 0; i < records.length; i++) {
141
+ for (var j = 0; j < records[i].addedNodes.length; j++) attachPlaying(records[i].addedNodes[j]);
142
+ }
143
+ }).observe(document.documentElement || document, { childList: true, subtree: true });
144
+ }
145
+ })();`;
146
+ }
147
+ //# sourceMappingURL=audioTap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audioTap.js","sourceRoot":"","sources":["../src/audioTap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,cAAc,CAAC,OAAe,EAAE,cAAc,GAAG,KAAK;IACpE,MAAM,KAAK,GAAG,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;IAChD,OAAO;6DACoD,KAAK;;;;+BAInC,KAAK;;;;;;;;;;;;;;;;;0BAiBV,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAkG3B,CAAC;AACP,CAAC"}
@@ -0,0 +1,94 @@
1
+ import type { Page } from 'patchright';
2
+ /**
3
+ * Local `getDataDir()`/`isInside()` — deliberately not imported from
4
+ * `mcp-servers/shared`: the browser package resolves `FLUJO_DATA_DIR` inline
5
+ * everywhere else (see `runtime.ts`'s `screenshotRoot()`), and does not carry
6
+ * the `@flujo-ai/mcp-shared` workspace dependency the other packages use.
7
+ */
8
+ export declare function getDataDir(): string;
9
+ export declare function isInside(root: string, candidate: string): boolean;
10
+ export type CaptureSource = {
11
+ kind: 'html';
12
+ html: string;
13
+ } | {
14
+ kind: 'url';
15
+ url: string;
16
+ };
17
+ /** Assert a single, stable PNG color type and return it. Never silently accepts a malformed image. */
18
+ export declare function pngColorType(png: Buffer): number;
19
+ /** Gates 1-3 of the local-capture ladder; gate 4 is `assertNavigationAllowed()` itself. */
20
+ export declare function assertLocalCaptureAllowed(resolvedPath: string, allowLocal: boolean): Promise<void>;
21
+ /**
22
+ * Resolve exactly one of `url` / `html` / `filePath` into a `CaptureSource`,
23
+ * applying local-source gating for `file://` and localhost/private-host
24
+ * inputs and the ordinary `assertNavigationAllowed()` gate for everything
25
+ * else.
26
+ */
27
+ export declare function resolveCaptureSource(args: {
28
+ url?: string;
29
+ html?: string;
30
+ filePath?: string;
31
+ allowLocal?: boolean;
32
+ }): Promise<CaptureSource>;
33
+ export type CapturePageOptions = {
34
+ fullPage: boolean;
35
+ clipSelector?: string;
36
+ waitFor?: string;
37
+ timeoutMs: number;
38
+ };
39
+ /**
40
+ * Determinism ladder: navigate → `waitForLoadState('load')` →
41
+ * `document.fonts.ready` → optional `waitFor` (selector or JS predicate,
42
+ * boolean-coerced and discarded — never returned to the caller, per D4) →
43
+ * screenshot with animations disabled.
44
+ */
45
+ export declare function captureDeterministicPng(page: Page, source: CaptureSource, options: CapturePageOptions): Promise<{
46
+ png: Buffer;
47
+ colorType: number;
48
+ }>;
49
+ /** Navigate/render a resolved source without capturing (used by `browser_capture_element_metrics`). */
50
+ export declare function navigateCaptureSource(page: Page, source: CaptureSource, timeoutMs: number): Promise<void>;
51
+ export type CaptureRegion = {
52
+ x: number;
53
+ y: number;
54
+ width: number;
55
+ height: number;
56
+ };
57
+ /** Region capture is a clipped `page.screenshot()`, not a manual pixel crop, so DPR/scroll never drift the result. */
58
+ export declare function captureRegionPng(page: Page, source: CaptureSource, region: CaptureRegion, timeoutMs: number): Promise<{
59
+ png: Buffer;
60
+ colorType: number;
61
+ }>;
62
+ export type ElementMetrics = {
63
+ selector: string;
64
+ found: boolean;
65
+ boundingBox?: {
66
+ x: number;
67
+ y: number;
68
+ width: number;
69
+ height: number;
70
+ };
71
+ clientRect?: {
72
+ top: number;
73
+ left: number;
74
+ right: number;
75
+ bottom: number;
76
+ width: number;
77
+ height: number;
78
+ };
79
+ scrollWidth?: number;
80
+ scrollHeight?: number;
81
+ isVisible?: boolean;
82
+ isInViewport?: boolean;
83
+ overflowX?: string;
84
+ overflowY?: string;
85
+ textOverflow?: boolean;
86
+ actionSafe?: boolean;
87
+ computed?: Record<string, string>;
88
+ };
89
+ export declare function evaluateElementMetrics(page: Page, selectors: string[]): Promise<ElementMetrics[]>;
90
+ export declare function sha256Hex(data: Buffer): string;
91
+ /** Default persistence root for still captures, mirroring `writeScreenshotArtifact()`'s layout. */
92
+ export declare function captureRoot(): string;
93
+ /** Write a capture artifact, confining any caller-supplied `outputPath` to the data dir or the capture root. */
94
+ export declare function writeCaptureArtifact(outputPath: string | undefined, defaultRelativePath: string[], data: Buffer): Promise<string>;
@@ -0,0 +1,302 @@
1
+ /**
2
+ * Deterministic still capture for the browser MCP server (#366).
3
+ *
4
+ * Kept out of `tools.ts`/`runtime.ts` to keep those under control, per the
5
+ * plan. Everything here operates on a `Page` handed in by the caller — either
6
+ * an ephemeral capture context (`createCaptureContext()` in `runtime.ts`) or
7
+ * an existing session's page — and never owns session lifecycle itself.
8
+ *
9
+ * Local-source gating (`assertLocalCaptureAllowed`) is the narrow, explicit
10
+ * bypass mentioned in the plan: it does not touch `assertNavigationAllowed()`,
11
+ * so ordinary `browser_open`/`browser_navigate` behaviour is unchanged. Four
12
+ * independent gates must all hold before a `file://` / localhost / private
13
+ * host is captured:
14
+ * 1. `allowLocal === true` on the call;
15
+ * 2. `FLUJO_BROWSER_ALLOW_LOCAL_CAPTURE` is truthy (default off);
16
+ * 3. the resolved realpath satisfies `isInside()` against the FLUJO data
17
+ * directory or an entry in `FLUJO_BROWSER_LOCAL_CAPTURE_ROOTS`;
18
+ * 4. everything else still goes through the ordinary `assertNavigationAllowed()`.
19
+ */
20
+ import { promises as fs } from 'node:fs';
21
+ import { createHash } from 'node:crypto';
22
+ import path from 'node:path';
23
+ import { fileURLToPath, pathToFileURL } from 'node:url';
24
+ import { BrowserMcpError, assertNavigationAllowed, enabledEnv } from './runtime.js';
25
+ /**
26
+ * Local `getDataDir()`/`isInside()` — deliberately not imported from
27
+ * `mcp-servers/shared`: the browser package resolves `FLUJO_DATA_DIR` inline
28
+ * everywhere else (see `runtime.ts`'s `screenshotRoot()`), and does not carry
29
+ * the `@flujo-ai/mcp-shared` workspace dependency the other packages use.
30
+ */
31
+ export function getDataDir() {
32
+ return path.resolve(process.env.FLUJO_DATA_DIR?.trim() || process.cwd());
33
+ }
34
+ export function isInside(root, candidate) {
35
+ const rel = path.relative(path.resolve(root), path.resolve(candidate));
36
+ return rel === '' || (!rel.startsWith('..') && !path.isAbsolute(rel));
37
+ }
38
+ const PNG_SIGNATURE = '89504e470d0a1a0a';
39
+ /** Byte offset of the IHDR color-type field: 8 (signature) + 4 (length) + 4 ("IHDR") + 4 (width) + 4 (height) + 1 (bit depth). */
40
+ const PNG_COLOR_TYPE_OFFSET = 25;
41
+ /** Assert a single, stable PNG color type and return it. Never silently accepts a malformed image. */
42
+ export function pngColorType(png) {
43
+ if (png.length <= PNG_COLOR_TYPE_OFFSET || png.subarray(0, 8).toString('hex') !== PNG_SIGNATURE) {
44
+ throw new BrowserMcpError('UNEXPECTED', 'The captured image is not a valid PNG.');
45
+ }
46
+ return png.readUInt8(PNG_COLOR_TYPE_OFFSET);
47
+ }
48
+ async function realpathIfExists(candidate) {
49
+ try {
50
+ return await fs.realpath(candidate);
51
+ }
52
+ catch {
53
+ return path.resolve(candidate);
54
+ }
55
+ }
56
+ function localCaptureRoots() {
57
+ const roots = [getDataDir()];
58
+ const raw = process.env.FLUJO_BROWSER_LOCAL_CAPTURE_ROOTS?.trim();
59
+ if (raw) {
60
+ for (const entry of raw.split(path.delimiter)) {
61
+ const trimmed = entry.trim();
62
+ if (trimmed)
63
+ roots.push(path.resolve(trimmed));
64
+ }
65
+ }
66
+ return roots;
67
+ }
68
+ function isLocalOrPrivateOrigin(url) {
69
+ if (url.protocol === 'file:')
70
+ return true;
71
+ const hostname = url.hostname.toLowerCase().replace(/^\[|\]$/g, '');
72
+ return hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '::1'
73
+ || hostname.endsWith('.localhost') || hostname.endsWith('.local');
74
+ }
75
+ /** Gates 1-3 of the local-capture ladder; gate 4 is `assertNavigationAllowed()` itself. */
76
+ export async function assertLocalCaptureAllowed(resolvedPath, allowLocal) {
77
+ if (!allowLocal) {
78
+ throw new BrowserMcpError('NAVIGATION_BLOCKED', 'Local file/localhost capture requires allowLocal=true.');
79
+ }
80
+ if (!enabledEnv('FLUJO_BROWSER_ALLOW_LOCAL_CAPTURE')) {
81
+ throw new BrowserMcpError('NAVIGATION_BLOCKED', 'Local capture is disabled by policy (set FLUJO_BROWSER_ALLOW_LOCAL_CAPTURE=1 to enable).');
82
+ }
83
+ const real = await realpathIfExists(resolvedPath);
84
+ const roots = localCaptureRoots();
85
+ if (!roots.some((root) => isInside(root, real))) {
86
+ throw new BrowserMcpError('NAVIGATION_BLOCKED', 'The local path is outside the allowed capture roots.');
87
+ }
88
+ }
89
+ /**
90
+ * Resolve exactly one of `url` / `html` / `filePath` into a `CaptureSource`,
91
+ * applying local-source gating for `file://` and localhost/private-host
92
+ * inputs and the ordinary `assertNavigationAllowed()` gate for everything
93
+ * else.
94
+ */
95
+ export async function resolveCaptureSource(args) {
96
+ const provided = [args.url, args.html, args.filePath].filter((value) => typeof value === 'string' && value.length > 0);
97
+ if (provided.length !== 1) {
98
+ throw new BrowserMcpError('INVALID_ARGUMENT', 'Provide exactly one of url, html, or filePath.');
99
+ }
100
+ if (typeof args.html === 'string') {
101
+ return { kind: 'html', html: args.html };
102
+ }
103
+ const allowLocal = args.allowLocal === true;
104
+ if (typeof args.filePath === 'string') {
105
+ const resolved = path.resolve(args.filePath);
106
+ await assertLocalCaptureAllowed(resolved, allowLocal);
107
+ return { kind: 'url', url: pathToFileURL(resolved).href };
108
+ }
109
+ const raw = args.url;
110
+ let parsed;
111
+ try {
112
+ parsed = new URL(raw);
113
+ }
114
+ catch {
115
+ throw new BrowserMcpError('NAVIGATION_BLOCKED', 'The URL is malformed.');
116
+ }
117
+ if (parsed.protocol === 'file:') {
118
+ await assertLocalCaptureAllowed(fileURLToPath(parsed), allowLocal);
119
+ return { kind: 'url', url: parsed.href };
120
+ }
121
+ if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
122
+ throw new BrowserMcpError('NAVIGATION_BLOCKED', 'Only HTTP, HTTPS, and file:// URLs are allowed.');
123
+ }
124
+ if (isLocalOrPrivateOrigin(parsed)) {
125
+ await assertLocalCaptureAllowed(raw, allowLocal);
126
+ return { kind: 'url', url: parsed.href };
127
+ }
128
+ // Gate 4: ordinary navigation policy, byte-for-byte unchanged, for anything
129
+ // that is not a local/private destination.
130
+ const allowedUrl = await assertNavigationAllowed(raw);
131
+ return { kind: 'url', url: allowedUrl.href };
132
+ }
133
+ function looksLikeJsPredicate(expression) {
134
+ return /[(){}=]/.test(expression) || /^\s*function\b/.test(expression) || expression.includes('=>');
135
+ }
136
+ /**
137
+ * Determinism ladder: navigate → `waitForLoadState('load')` →
138
+ * `document.fonts.ready` → optional `waitFor` (selector or JS predicate,
139
+ * boolean-coerced and discarded — never returned to the caller, per D4) →
140
+ * screenshot with animations disabled.
141
+ */
142
+ export async function captureDeterministicPng(page, source, options) {
143
+ const timeout = options.timeoutMs;
144
+ if (source.kind === 'html') {
145
+ await page.setContent(source.html, { waitUntil: 'load', timeout });
146
+ }
147
+ else {
148
+ await page.goto(source.url, { waitUntil: 'load', timeout });
149
+ }
150
+ await page.waitForLoadState('load', { timeout }).catch(() => undefined);
151
+ // No `dom` lib in this workspace's tsconfig, so the fonts-ready wait is a
152
+ // fixed string body rather than a typed arrow function (same rationale as
153
+ // ELEMENT_METRICS_SCRIPT below).
154
+ await page.evaluate('(document.fonts && document.fonts.ready) || Promise.resolve()').catch(() => undefined);
155
+ if (options.waitFor) {
156
+ if (looksLikeJsPredicate(options.waitFor)) {
157
+ // The predicate's return value is intentionally discarded: this waits
158
+ // for a boolean-truthy condition and never leaks arbitrary evaluation
159
+ // results back to the caller (D4 — no general JS-evaluate tool).
160
+ await page.waitForFunction(options.waitFor, undefined, { timeout });
161
+ }
162
+ else {
163
+ await page.waitForSelector(options.waitFor, { timeout });
164
+ }
165
+ }
166
+ let handle = null;
167
+ try {
168
+ let png;
169
+ if (options.clipSelector) {
170
+ handle = await page.waitForSelector(options.clipSelector, { timeout });
171
+ if (!handle)
172
+ throw new BrowserMcpError('NOT_FOUND', 'clipSelector did not match any element.');
173
+ await handle.scrollIntoViewIfNeeded({ timeout }).catch(() => undefined);
174
+ png = await handle.screenshot({ type: 'png', animations: 'disabled', caret: 'hide', scale: 'css', timeout });
175
+ }
176
+ else {
177
+ png = await page.screenshot({
178
+ type: 'png',
179
+ fullPage: options.fullPage,
180
+ animations: 'disabled',
181
+ caret: 'hide',
182
+ scale: 'css',
183
+ timeout,
184
+ });
185
+ }
186
+ return { png, colorType: pngColorType(png) };
187
+ }
188
+ finally {
189
+ await handle?.dispose().catch(() => undefined);
190
+ }
191
+ }
192
+ /** Navigate/render a resolved source without capturing (used by `browser_capture_element_metrics`). */
193
+ export async function navigateCaptureSource(page, source, timeoutMs) {
194
+ if (source.kind === 'html') {
195
+ await page.setContent(source.html, { waitUntil: 'load', timeout: timeoutMs });
196
+ }
197
+ else {
198
+ await page.goto(source.url, { waitUntil: 'load', timeout: timeoutMs });
199
+ }
200
+ await page.waitForLoadState('load', { timeout: timeoutMs }).catch(() => undefined);
201
+ }
202
+ /** Region capture is a clipped `page.screenshot()`, not a manual pixel crop, so DPR/scroll never drift the result. */
203
+ export async function captureRegionPng(page, source, region, timeoutMs) {
204
+ if (source.kind === 'html') {
205
+ await page.setContent(source.html, { waitUntil: 'load', timeout: timeoutMs });
206
+ }
207
+ else {
208
+ await page.goto(source.url, { waitUntil: 'load', timeout: timeoutMs });
209
+ }
210
+ await page.waitForLoadState('load', { timeout: timeoutMs }).catch(() => undefined);
211
+ const png = await page.screenshot({
212
+ type: 'png',
213
+ animations: 'disabled',
214
+ caret: 'hide',
215
+ scale: 'css',
216
+ clip: region,
217
+ timeout: timeoutMs,
218
+ });
219
+ return { png, colorType: pngColorType(png) };
220
+ }
221
+ /**
222
+ * A single, fixed, non-parameterised `page.evaluate` script body, kept as a
223
+ * string (this file's `tsconfig.json` has no `dom` lib, and the script only
224
+ * ever runs inside the page, never in this Node process). Selectors are
225
+ * passed as *data* arguments only — never string-concatenated into code — so
226
+ * this cannot become a general JS-evaluate primitive (D4).
227
+ */
228
+ const ELEMENT_METRICS_SCRIPT = `(function(selectors){
229
+ function overflowClass(value, scrollSize, clientSize){
230
+ if (value === "visible") return "visible";
231
+ if (scrollSize > clientSize) return value === "scroll" ? "scroll" : "clipped";
232
+ return value;
233
+ }
234
+ return selectors.map(function(selector){
235
+ var el = document.querySelector(selector);
236
+ if (!el) return { selector: selector, found: false };
237
+ var rect = el.getBoundingClientRect();
238
+ var style = window.getComputedStyle(el);
239
+ var viewportW = window.innerWidth, viewportH = window.innerHeight;
240
+ var isVisible = style.visibility !== "hidden" && style.display !== "none" && rect.width > 0 && rect.height > 0;
241
+ var isInViewport = rect.top < viewportH && rect.bottom > 0 && rect.left < viewportW && rect.right > 0;
242
+ return {
243
+ selector: selector,
244
+ found: true,
245
+ boundingBox: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },
246
+ clientRect: { top: rect.top, left: rect.left, right: rect.right, bottom: rect.bottom, width: rect.width, height: rect.height },
247
+ scrollWidth: el.scrollWidth,
248
+ scrollHeight: el.scrollHeight,
249
+ isVisible: isVisible,
250
+ isInViewport: isInViewport,
251
+ overflowX: overflowClass(style.overflowX, el.scrollWidth, el.clientWidth),
252
+ overflowY: overflowClass(style.overflowY, el.scrollHeight, el.clientHeight),
253
+ textOverflow: el.scrollWidth > el.clientWidth || el.scrollHeight > el.clientHeight,
254
+ actionSafe: isVisible && isInViewport,
255
+ computed: {
256
+ fontSize: style.fontSize,
257
+ lineHeight: style.lineHeight,
258
+ color: style.color,
259
+ backgroundColor: style.backgroundColor,
260
+ opacity: style.opacity,
261
+ zIndex: style.zIndex,
262
+ transform: style.transform,
263
+ display: style.display,
264
+ position: style.position,
265
+ },
266
+ };
267
+ });
268
+ })`;
269
+ export async function evaluateElementMetrics(page, selectors) {
270
+ return page.evaluate(ELEMENT_METRICS_SCRIPT, selectors);
271
+ }
272
+ export function sha256Hex(data) {
273
+ return createHash('sha256').update(data).digest('hex');
274
+ }
275
+ /** Default persistence root for still captures, mirroring `writeScreenshotArtifact()`'s layout. */
276
+ export function captureRoot() {
277
+ const configured = process.env.FLUJO_BROWSER_SCREENSHOT_DIR?.trim();
278
+ if (configured)
279
+ return path.resolve(configured);
280
+ const dataRoot = process.env.FLUJO_DATA_DIR?.trim() || process.cwd();
281
+ return path.resolve(dataRoot, 'screenshots', 'browser');
282
+ }
283
+ /** Write a capture artifact, confining any caller-supplied `outputPath` to the data dir or the capture root. */
284
+ export async function writeCaptureArtifact(outputPath, defaultRelativePath, data) {
285
+ let filePath;
286
+ if (outputPath) {
287
+ const resolved = path.resolve(outputPath);
288
+ const dataDir = getDataDir();
289
+ const root = captureRoot();
290
+ if (!isInside(dataDir, resolved) && !isInside(root, resolved)) {
291
+ throw new BrowserMcpError('INVALID_ARGUMENT', 'outputPath must be inside the FLUJO data directory or the browser screenshot root.');
292
+ }
293
+ filePath = resolved;
294
+ }
295
+ else {
296
+ filePath = path.join(captureRoot(), ...defaultRelativePath);
297
+ }
298
+ await fs.mkdir(path.dirname(filePath), { recursive: true });
299
+ await fs.writeFile(filePath, data);
300
+ return filePath;
301
+ }
302
+ //# sourceMappingURL=capture.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capture.js","sourceRoot":"","sources":["../src/capture.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAExD,OAAO,EAAE,eAAe,EAAE,uBAAuB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAEpF;;;;;GAKG;AACH,MAAM,UAAU,UAAU;IACxB,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,EAAE,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;AAC3E,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,IAAY,EAAE,SAAiB;IACtD,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;IACvE,OAAO,GAAG,KAAK,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;AACxE,CAAC;AAED,MAAM,aAAa,GAAG,kBAAkB,CAAC;AACzC,kIAAkI;AAClI,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAMjC,sGAAsG;AACtG,MAAM,UAAU,YAAY,CAAC,GAAW;IACtC,IAAI,GAAG,CAAC,MAAM,IAAI,qBAAqB,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CA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,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,UAA8B,EAC9B,mBAA6B,EAC7B,IAAY;IAEZ,IAAI,QAAgB,CAAC;IACrB,IAAI,UAAU,EAAE,CAAC;QACf,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC1C,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;QAC7B,MAAM,IAAI,GAAG,WAAW,EAAE,CAAC;QAC3B,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,CAAC;YAC9D,MAAM,IAAI,eAAe,CAAC,kBAAkB,EAAE,oFAAoF,CAAC,CAAC;QACtI,CAAC;QACD,QAAQ,GAAG,QAAQ,CAAC;IACtB,CAAC;SAAM,CAAC;QACN,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,GAAG,mBAAmB,CAAC,CAAC;IAC9D,CAAC;IACD,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5D,MAAM,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IACnC,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -0,0 +1,28 @@
1
+ export type BrowserGatewayEndpoint = {
2
+ /** Origin the MCP App connects to, e.g. `http://127.0.0.1:53411`. */
3
+ origin: string;
4
+ /** Bearer token required on every gateway request. */
5
+ token: string;
6
+ };
7
+ /** Exported for tests: whether the escape hatch is active. */
8
+ export declare function browserSandboxAllowAll(): boolean;
9
+ /**
10
+ * Start (or reuse) the loopback gateway. Resolves to `undefined` when streaming
11
+ * is disabled or the listener cannot bind, so the MCP App can fall back to the
12
+ * screenshot poll loop instead of failing to render at all.
13
+ */
14
+ export declare function ensureBrowserGateway(): Promise<BrowserGatewayEndpoint | undefined>;
15
+ /** Current endpoint, or `undefined` when the gateway has not started. */
16
+ export declare function browserGatewayEndpoint(): BrowserGatewayEndpoint | undefined;
17
+ /**
18
+ * Install the main-world audio interception before a navigation can create an
19
+ * AudioContext or fire a media element's play event. Capture remains muted
20
+ * until a client opens /audio. Failure is intentionally non-fatal: browser
21
+ * navigation and the screenshot stream must continue when audio is unavailable.
22
+ */
23
+ export declare function prepareBrowserAudioStream(sessionId: string): Promise<void>;
24
+ export declare function shutdownBrowserGateway(): Promise<void>;
25
+ /** Exported for tests: host speaker output stays muted unless opted in. */
26
+ export declare function browserAudioEnabled(): boolean;
27
+ /** Exported for tests: whether the page audio tap streams to the app. */
28
+ export declare function browserAudioStreamEnabled(): boolean;