@replohq/sandbox-runtime 1.6.5 → 1.6.7

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.
@@ -1,28 +1,66 @@
1
1
  "use client";
2
2
  import * as React from "react";
3
+ import {
4
+ isAllowedEditorMessage,
5
+ isAllowedEditorOrigin
6
+ } from "./annotations/bridgeGate";
3
7
  const RED_CHROME_SELECTOR = '[data-next-badge][data-error="true"], [data-nextjs-dialog]';
4
8
  const BLOCKING_ERROR_SELECTOR = "[data-nextjs-dialog]";
5
9
  const STATUS_LATCH_MS = 500;
10
+ function findInitialEditorOrigin() {
11
+ if (window.self === window.top) {
12
+ return null;
13
+ }
14
+ const ancestorOrigin = "ancestorOrigins" in window.location ? window.location.ancestorOrigins.item(0) : null;
15
+ return [ancestorOrigin, getOriginOrNull(document.referrer)].find((origin) => {
16
+ return origin !== null && isAllowedEditorOrigin(origin);
17
+ }) ?? null;
18
+ }
19
+ function getOriginOrNull(url) {
20
+ try {
21
+ return new URL(url).origin;
22
+ } catch {
23
+ return null;
24
+ }
25
+ }
6
26
  function NextErrorReporter() {
7
27
  React.useEffect(() => {
28
+ let editorOrigin = findInitialEditorOrigin();
8
29
  let lastStatus = null;
9
30
  let shadowObserver = null;
10
31
  let observedRoot = null;
11
32
  let pendingPost = null;
12
- const postNow = (status) => {
13
- if (status === lastStatus) {
33
+ const deliver = () => {
34
+ if (editorOrigin === null || lastStatus === null) {
14
35
  return;
15
36
  }
16
- lastStatus = status;
17
37
  window.parent.postMessage(
18
38
  {
19
39
  type: "replo:preview:status",
20
- status,
40
+ status: lastStatus,
21
41
  route: window.location.pathname
22
42
  },
23
- "*"
43
+ editorOrigin
24
44
  );
25
45
  };
46
+ const postNow = (status) => {
47
+ if (status === lastStatus) {
48
+ return;
49
+ }
50
+ lastStatus = status;
51
+ deliver();
52
+ };
53
+ const handleParentMessage = (event) => {
54
+ if (event.source !== window.parent || !isAllowedEditorMessage(event)) {
55
+ return;
56
+ }
57
+ if (event.origin === editorOrigin) {
58
+ return;
59
+ }
60
+ editorOrigin = event.origin;
61
+ deliver();
62
+ };
63
+ window.addEventListener("message", handleParentMessage);
26
64
  const post = (status) => {
27
65
  if (pendingPost) {
28
66
  if (pendingPost.status === status) {
@@ -77,6 +115,7 @@ function NextErrorReporter() {
77
115
  });
78
116
  syncOverlayState();
79
117
  return () => {
118
+ window.removeEventListener("message", handleParentMessage);
80
119
  lightObserver.disconnect();
81
120
  shadowObserver?.disconnect();
82
121
  if (pendingPost) {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../NextErrorReporter.tsx"],
4
- "sourcesContent": ["\"use client\";\n\nimport * as React from \"react\";\n\n/**\n * NOTE (Max, 2026-06-10): This component sends post messages to its embedder (website-builder miniapp)\n * so that it can render a loading / error UI if there's an error on this page.\n *\n * Ideally, we wouldn't need any update to the sandbox runtime to achieve this: the miniapp would just read the\n * iframe's content and detect whenever there's a nextjs error overlay.\n * But the preview runs cross-origin from the editor, so the editor can't read the iframe's\n * DOM (browser security).\n *\n * This component has observers that detect when the nextjs error overlay appears or\n * disappears, and sends a post message with a status:\n * - `status`: \"error\" while Next's dev overlay opens its blocking error dialog\n * (a real page break \u2014 see the selectors below for why the badge's issue\n * count is deliberately NOT used: it also counts recovered loader misses)\n * - `status`: \"ok\" otherwise. Cleared by Fast Refresh on a fix, so it's also the\n * recovery signal (agent fixed the error, so it's the error -> ok transition)\n *\n * It also hides Next's dev error overlay (`<nextjs-portal>`) at the source the\n * instant an error appears, so the red bubble never paints \u2014 the MutationObserver\n * callback runs as a microtask before paint. `data-error` stays queryable while\n * hidden, so detection is unaffected;\n *\n * The overlay lives in `<nextjs-portal>`'s shadow root, which Next can recreate,\n * so we re-attach the shadow observer whenever it hands us a new root. No polling.\n *\n * This must be mounted OUTSIDE the error boundary (see ReploProvider) so it keeps\n * reporting while the boundary is caught (and showing its neutral cover).\n *\n * I'm unsatisfied with this approach: observing for the nextjs-portal is brittle and ugly.\n * Ideally, the ClientErrorBoundary, which hooks into the render cycle, in componentDidCatch, would\n * just report a post message to the miniapp. I prototyped that, the error detection works\n * great (ok -> error transition).\n * But the error -> ok transition doesn't work for Server components (it only does for Client\n * components). Here's a slack thread with me <> Gabe on it:\n * https://replohq.slack.com/archives/C03AACVP08Y/p1781154057832689?thread_ts=1781029224.564489&cid=C03AACVP08Y.\n */\n// NOTE (Max, 2026-08-04): <nextjs-portal> surfaces two very different things,\n// and only one of them means the page is actually broken:\n// - the dev-tools badge (`[data-next-badge][data-error=\"true\"]`) lights for\n// EVERY collected issue, including a server-side loader error that React\n// already recovered from by streaming the LoaderErrorBoundary fallback. That\n// is a graceful, recoverable miss (product unpublished, deleted collection,\n// \u2026) \u2014 the page renders fine \u2014 and it must NOT be reported as a page error.\n// - the error overlay dialog (`[data-nextjs-dialog]`) only mounts when Next\n// auto-opens the overlay for a genuinely blocking error: the app shell's\n// error boundary catching an uncaught render crash, an unrecoverable SSR\n// error (missing root tags), or a build error. Next never auto-opens the\n// dialog for a recovered error. Verified against next@16.1.7 (the version\n// the platform SDK packages and most templates pin) and next@15.3.8: the sole auto-open\n// is AppDevOverlayErrorBoundary's componentDidCatch -> openErrorOverlay,\n// i.e. the shell boundary, which a nested LoaderErrorBoundary never reaches\n// (a caught loader miss only increments the badge count). The badge count\n// opens the dialog only on an explicit user click.\n// So the open dialog \u2014 not the badge's issue count \u2014 is the fatal-vs-recoverable\n// discriminator. Keying off the badge reported recoverable loader misses as\n// full-page errors, blanking a preview that had actually rendered its fallback.\n//\n// We still *hide* the whole portal whenever Next paints red chrome (the errored\n// badge OR the dialog) so no dev overlay bleeds into the preview \u2014 a recovered\n// loader miss shouldn't flash a red dot either. Only the blocking dialog is\n// reported upward as a page error.\nconst RED_CHROME_SELECTOR =\n '[data-next-badge][data-error=\"true\"], [data-nextjs-dialog]';\nconst BLOCKING_ERROR_SELECTOR = \"[data-nextjs-dialog]\";\n\n// HMR portal churn flips the overlay for milliseconds in both directions; only a state that persists this long is real.\nconst STATUS_LATCH_MS = 500;\n\ntype PreviewStatus = \"ok\" | \"error\";\n\nexport function NextErrorReporter() {\n // eslint-disable-next-line replo/no-use-effect -- Observes Next's dev error overlay (a shadow-DOM node outside React's tree) and relays its state to the cross-origin embedder. No React alternative applies.\n React.useEffect(() => {\n let lastStatus: PreviewStatus | null = null;\n let shadowObserver: MutationObserver | null = null;\n let observedRoot: ShadowRoot | null = null;\n let pendingPost: { status: PreviewStatus; timeoutId: number } | null = null;\n\n const postNow = (status: PreviewStatus) => {\n if (status === lastStatus) {\n return;\n }\n lastStatus = status;\n window.parent.postMessage(\n {\n type: \"replo:preview:status\",\n status,\n route: window.location.pathname,\n },\n \"*\",\n );\n };\n\n // Latch every transition (the opposite observation cancels a pending one) \u2014 a false error <-> ok flip makes the editor reload the preview. Only the initial \"ok\" posts immediately, as the readiness signal.\n const post = (status: PreviewStatus) => {\n if (pendingPost) {\n if (pendingPost.status === status) {\n return;\n }\n window.clearTimeout(pendingPost.timeoutId);\n pendingPost = null;\n }\n if (status === lastStatus) {\n return;\n }\n if (lastStatus === null && status === \"ok\") {\n postNow(\"ok\");\n return;\n }\n const timeoutId = window.setTimeout(() => {\n pendingPost = null;\n postNow(status);\n }, STATUS_LATCH_MS);\n pendingPost = { status, timeoutId };\n };\n\n // NOTE (Max, 2026-06-10): Reads the dev overlay's current error state and\n // propagates it \u2014 re-attach the shadow observer to the live root, hide the\n // portal while erroring, and post ok/error up to the editor. Runs on init and\n // on every observed DOM mutation.\n const syncOverlayState = () => {\n const portal = document.getElementsByTagName(\"nextjs-portal\")[0];\n if (!(portal instanceof HTMLElement)) {\n post(\"ok\");\n return;\n }\n // NOTE (Max, 2026-06-10): Re-attach whenever Next hands us a fresh shadow\n // root, else we'd keep watching a detached one after the overlay is\n // recreated.\n const root = portal.shadowRoot;\n if (root && root !== observedRoot) {\n shadowObserver?.disconnect();\n shadowObserver = new MutationObserver(syncOverlayState);\n shadowObserver.observe(root, {\n childList: true,\n subtree: true,\n attributes: true,\n attributeFilter: [\"data-error\"],\n });\n observedRoot = root;\n }\n // NOTE (Max, 2026-06-10): Hide the dev overlay at the source so the red\n // bubble never paints \u2014 for any red chrome, including a recovered miss's\n // errored badge.\n portal.style.display = portal.shadowRoot?.querySelector(\n RED_CHROME_SELECTOR,\n )\n ? \"none\"\n : \"\";\n // Only the blocking overlay dialog means the page actually broke; the\n // badge's issue count also covers recovered loader misses (see selectors).\n const hasBlockingError = Boolean(\n portal.shadowRoot?.querySelector(BLOCKING_ERROR_SELECTOR),\n );\n post(hasBlockingError ? \"error\" : \"ok\");\n };\n\n // NOTE (Max, 2026-06-10): Catches the portal being added/removed in the light\n // DOM; the re-attached shadow observer catches in-overlay changes.\n const lightObserver = new MutationObserver(syncOverlayState);\n lightObserver.observe(document.documentElement, {\n childList: true,\n subtree: true,\n });\n syncOverlayState();\n\n return () => {\n lightObserver.disconnect();\n shadowObserver?.disconnect();\n if (pendingPost) {\n window.clearTimeout(pendingPost.timeoutId);\n }\n };\n }, []);\n\n return null;\n}\n"],
5
- "mappings": ";AAEA,YAAY,WAAW;AA+DvB,MAAM,sBACJ;AACF,MAAM,0BAA0B;AAGhC,MAAM,kBAAkB;AAIjB,SAAS,oBAAoB;AAElC,QAAM,UAAU,MAAM;AACpB,QAAI,aAAmC;AACvC,QAAI,iBAA0C;AAC9C,QAAI,eAAkC;AACtC,QAAI,cAAmE;AAEvE,UAAM,UAAU,CAAC,WAA0B;AACzC,UAAI,WAAW,YAAY;AACzB;AAAA,MACF;AACA,mBAAa;AACb,aAAO,OAAO;AAAA,QACZ;AAAA,UACE,MAAM;AAAA,UACN;AAAA,UACA,OAAO,OAAO,SAAS;AAAA,QACzB;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAGA,UAAM,OAAO,CAAC,WAA0B;AACtC,UAAI,aAAa;AACf,YAAI,YAAY,WAAW,QAAQ;AACjC;AAAA,QACF;AACA,eAAO,aAAa,YAAY,SAAS;AACzC,s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";\n\nimport {\n isAllowedEditorMessage,\n isAllowedEditorOrigin,\n} from \"./annotations/bridgeGate\";\n\n/**\n * NOTE (Max, 2026-06-10): This component sends post messages to its embedder (website-builder miniapp)\n * so that it can render a loading / error UI if there's an error on this page.\n *\n * Ideally, we wouldn't need any update to the sandbox runtime to achieve this: the miniapp would just read the\n * iframe's content and detect whenever there's a nextjs error overlay.\n * But the preview runs cross-origin from the editor, so the editor can't read the iframe's\n * DOM (browser security).\n *\n * This component has observers that detect when the nextjs error overlay appears or\n * disappears, and sends a post message with a status:\n * - `status`: \"error\" while Next's dev overlay opens its blocking error dialog\n * (a real page break \u2014 see the selectors below for why the badge's issue\n * count is deliberately NOT used: it also counts recovered loader misses)\n * - `status`: \"ok\" otherwise. Cleared by Fast Refresh on a fix, so it's also the\n * recovery signal (agent fixed the error, so it's the error -> ok transition)\n *\n * It also hides Next's dev error overlay (`<nextjs-portal>`) at the source the\n * instant an error appears, so the red bubble never paints \u2014 the MutationObserver\n * callback runs as a microtask before paint. `data-error` stays queryable while\n * hidden, so detection is unaffected;\n *\n * The overlay lives in `<nextjs-portal>`'s shadow root, which Next can recreate,\n * so we re-attach the shadow observer whenever it hands us a new root. No polling.\n *\n * This must be mounted OUTSIDE the error boundary (see ReploProvider) so it keeps\n * reporting while the boundary is caught (and showing its neutral cover).\n *\n * I'm unsatisfied with this approach: observing for the nextjs-portal is brittle and ugly.\n * Ideally, the ClientErrorBoundary, which hooks into the render cycle, in componentDidCatch, would\n * just report a post message to the miniapp. I prototyped that, the error detection works\n * great (ok -> error transition).\n * But the error -> ok transition doesn't work for Server components (it only does for Client\n * components). Here's a slack thread with me <> Gabe on it:\n * https://replohq.slack.com/archives/C03AACVP08Y/p1781154057832689?thread_ts=1781029224.564489&cid=C03AACVP08Y.\n */\n// NOTE (Max, 2026-08-04): <nextjs-portal> surfaces two very different things,\n// and only one of them means the page is actually broken:\n// - the dev-tools badge (`[data-next-badge][data-error=\"true\"]`) lights for\n// EVERY collected issue, including a server-side loader error that React\n// already recovered from by streaming the LoaderErrorBoundary fallback. That\n// is a graceful, recoverable miss (product unpublished, deleted collection,\n// \u2026) \u2014 the page renders fine \u2014 and it must NOT be reported as a page error.\n// - the error overlay dialog (`[data-nextjs-dialog]`) only mounts when Next\n// auto-opens the overlay for a genuinely blocking error: the app shell's\n// error boundary catching an uncaught render crash, an unrecoverable SSR\n// error (missing root tags), or a build error. Next never auto-opens the\n// dialog for a recovered error. Verified against next@16.1.7 (the version\n// the platform SDK packages and most templates pin) and next@15.3.8: the sole auto-open\n// is AppDevOverlayErrorBoundary's componentDidCatch -> openErrorOverlay,\n// i.e. the shell boundary, which a nested LoaderErrorBoundary never reaches\n// (a caught loader miss only increments the badge count). The badge count\n// opens the dialog only on an explicit user click.\n// So the open dialog \u2014 not the badge's issue count \u2014 is the fatal-vs-recoverable\n// discriminator. Keying off the badge reported recoverable loader misses as\n// full-page errors, blanking a preview that had actually rendered its fallback.\n//\n// We still *hide* the whole portal whenever Next paints red chrome (the errored\n// badge OR the dialog) so no dev overlay bleeds into the preview \u2014 a recovered\n// loader miss shouldn't flash a red dot either. Only the blocking dialog is\n// reported upward as a page error.\nconst RED_CHROME_SELECTOR =\n '[data-next-badge][data-error=\"true\"], [data-nextjs-dialog]';\nconst BLOCKING_ERROR_SELECTOR = \"[data-nextjs-dialog]\";\n\n// HMR portal churn flips the overlay for milliseconds in both directions; only a state that persists this long is real.\nconst STATUS_LATCH_MS = 500;\n\ntype PreviewStatus = \"ok\" | \"error\";\n\n// The embedder's origin as the browser reports it, trusted only if it is an allowed editor. `ancestorOrigins` names the actual parent and survives referrer policies and in-frame navigations, but Firefox lacks it; the referrer covers Firefox, the same way the annotation layer announces itself.\nfunction findInitialEditorOrigin(): string | null {\n // A top-level page has no editor to report to.\n if (window.self === window.top) {\n return null;\n }\n const ancestorOrigin =\n \"ancestorOrigins\" in window.location\n ? window.location.ancestorOrigins.item(0)\n : null;\n return (\n [ancestorOrigin, getOriginOrNull(document.referrer)].find((origin) => {\n return origin !== null && isAllowedEditorOrigin(origin);\n }) ?? null\n );\n}\n\nfunction getOriginOrNull(url: string): string | null {\n try {\n return new URL(url).origin;\n } catch {\n return null;\n }\n}\n\nexport function NextErrorReporter() {\n // eslint-disable-next-line replo/no-use-effect -- Observes Next's dev error overlay (a shadow-DOM node outside React's tree) and relays its state to the cross-origin embedder. No React alternative applies.\n React.useEffect(() => {\n let editorOrigin = findInitialEditorOrigin();\n let lastStatus: PreviewStatus | null = null;\n let shadowObserver: MutationObserver | null = null;\n let observedRoot: ShadowRoot | null = null;\n let pendingPost: { status: PreviewStatus; timeoutId: number } | null = null;\n\n // Status and route are only for the editor, so they never go out with a wildcard target; without a trusted origin the status is kept and delivered once one is learned.\n const deliver = () => {\n if (editorOrigin === null || lastStatus === null) {\n return;\n }\n window.parent.postMessage(\n {\n type: \"replo:preview:status\",\n status: lastStatus,\n route: window.location.pathname,\n },\n editorOrigin,\n );\n };\n\n const postNow = (status: PreviewStatus) => {\n if (status === lastStatus) {\n return;\n }\n lastStatus = status;\n deliver();\n };\n\n // Covers a missing or stale referrer (Firefox after an in-frame navigation): a message from the parent window at an allowed origin proves where the editor lives, the same capture the annotation layer uses for its replies.\n const handleParentMessage = (event: MessageEvent) => {\n if (event.source !== window.parent || !isAllowedEditorMessage(event)) {\n return;\n }\n if (event.origin === editorOrigin) {\n return;\n }\n editorOrigin = event.origin;\n deliver();\n };\n window.addEventListener(\"message\", handleParentMessage);\n\n // Latch every transition (the opposite observation cancels a pending one) \u2014 a false error <-> ok flip makes the editor reload the preview. Only the initial \"ok\" posts immediately, as the readiness signal.\n const post = (status: PreviewStatus) => {\n if (pendingPost) {\n if (pendingPost.status === status) {\n return;\n }\n window.clearTimeout(pendingPost.timeoutId);\n pendingPost = null;\n }\n if (status === lastStatus) {\n return;\n }\n if (lastStatus === null && status === \"ok\") {\n postNow(\"ok\");\n return;\n }\n const timeoutId = window.setTimeout(() => {\n pendingPost = null;\n postNow(status);\n }, STATUS_LATCH_MS);\n pendingPost = { status, timeoutId };\n };\n\n // NOTE (Max, 2026-06-10): Reads the dev overlay's current error state and\n // propagates it \u2014 re-attach the shadow observer to the live root, hide the\n // portal while erroring, and post ok/error up to the editor. Runs on init and\n // on every observed DOM mutation.\n const syncOverlayState = () => {\n const portal = document.getElementsByTagName(\"nextjs-portal\")[0];\n if (!(portal instanceof HTMLElement)) {\n post(\"ok\");\n return;\n }\n // NOTE (Max, 2026-06-10): Re-attach whenever Next hands us a fresh shadow\n // root, else we'd keep watching a detached one after the overlay is\n // recreated.\n const root = portal.shadowRoot;\n if (root && root !== observedRoot) {\n shadowObserver?.disconnect();\n shadowObserver = new MutationObserver(syncOverlayState);\n shadowObserver.observe(root, {\n childList: true,\n subtree: true,\n attributes: true,\n attributeFilter: [\"data-error\"],\n });\n observedRoot = root;\n }\n // NOTE (Max, 2026-06-10): Hide the dev overlay at the source so the red\n // bubble never paints \u2014 for any red chrome, including a recovered miss's\n // errored badge.\n portal.style.display = portal.shadowRoot?.querySelector(\n RED_CHROME_SELECTOR,\n )\n ? \"none\"\n : \"\";\n // Only the blocking overlay dialog means the page actually broke; the\n // badge's issue count also covers recovered loader misses (see selectors).\n const hasBlockingError = Boolean(\n portal.shadowRoot?.querySelector(BLOCKING_ERROR_SELECTOR),\n );\n post(hasBlockingError ? \"error\" : \"ok\");\n };\n\n // NOTE (Max, 2026-06-10): Catches the portal being added/removed in the light\n // DOM; the re-attached shadow observer catches in-overlay changes.\n const lightObserver = new MutationObserver(syncOverlayState);\n lightObserver.observe(document.documentElement, {\n childList: true,\n subtree: true,\n });\n syncOverlayState();\n\n return () => {\n window.removeEventListener(\"message\", handleParentMessage);\n lightObserver.disconnect();\n shadowObserver?.disconnect();\n if (pendingPost) {\n window.clearTimeout(pendingPost.timeoutId);\n }\n };\n }, []);\n\n return null;\n}\n"],
5
+ "mappings": ";AAEA,YAAY,WAAW;AAEvB;AAAA,EACE;AAAA,EACA;AAAA,OACK;AA+DP,MAAM,sBACJ;AAC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AAAA,MAC3C;AAAA,IACF;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,86 @@
1
+ export declare const VIEWPORT_SNAPSHOT_REQUEST = "replo:viewport-snapshot:request";
2
+ export declare const VIEWPORT_SNAPSHOT_RESPONSE = "replo:viewport-snapshot:response";
3
+ /**
4
+ * Levels of iframe nesting a capture request fans out to below the requester.
5
+ * 2 covers the deepest product surface: agent-ui → miniapp → builder preview.
6
+ */
7
+ export declare const VIEWPORT_SNAPSHOT_MAX_DEPTH = 2;
8
+ export interface ViewportSnapshotRequestMessage {
9
+ type: typeof VIEWPORT_SNAPSHOT_REQUEST;
10
+ requestId: string;
11
+ frameIndex: number;
12
+ remainingDepth: number;
13
+ }
14
+ export interface ViewportFrameRect {
15
+ x: number;
16
+ y: number;
17
+ width: number;
18
+ height: number;
19
+ }
20
+ /** One frame's serialized DOM plus its own captured child frames, recursively. */
21
+ export interface ViewportFrameCapture {
22
+ snapshot: unknown;
23
+ childFrames: ViewportChildFrame[];
24
+ }
25
+ export interface ViewportChildFrame {
26
+ frameIndex: number;
27
+ rect: ViewportFrameRect;
28
+ capture: ViewportFrameCapture;
29
+ }
30
+ export interface ViewportSnapshotResponseMessage {
31
+ type: typeof VIEWPORT_SNAPSHOT_RESPONSE;
32
+ requestId: string;
33
+ frameIndex: number;
34
+ capture: ViewportFrameCapture | null;
35
+ }
36
+ interface RelayMessageListener {
37
+ (event: {
38
+ data: unknown;
39
+ source: unknown;
40
+ origin?: string;
41
+ }): void;
42
+ }
43
+ interface RelayWindow {
44
+ readonly parent: unknown;
45
+ readonly frames: ArrayLike<{
46
+ postMessage: (message: unknown, targetOrigin: string) => void;
47
+ }>;
48
+ addEventListener(type: "message", listener: RelayMessageListener): void;
49
+ removeEventListener(type: "message", listener: RelayMessageListener): void;
50
+ setTimeout(listener: () => void, timeout: number): number;
51
+ clearTimeout(timeoutId: number): void;
52
+ }
53
+ /**
54
+ * Default trust check for who may request this frame's DOM: Replo app origins
55
+ * plus local dev hosts. Runtimes embedded in arbitrary third-party pages
56
+ * (published sites) silently ignore requests from anything else.
57
+ */
58
+ export declare function isTrustedViewportSnapshotRequester(origin: string): boolean;
59
+ /**
60
+ * Ask every direct child frame for its capture (each child cascades to its own
61
+ * children while `remainingDepth` allows) and collect the responses. Resolves
62
+ * at the timeout with whatever arrived — a frame running an older runtime
63
+ * simply never answers and is omitted.
64
+ */
65
+ export declare function requestChildViewportSnapshots({ targetWindow, requestId, timeoutMs, remainingDepth, }: {
66
+ targetWindow: RelayWindow;
67
+ requestId: string;
68
+ timeoutMs: number;
69
+ remainingDepth?: number;
70
+ }): Promise<{
71
+ frameIndex: number;
72
+ capture: ViewportFrameCapture;
73
+ }[]>;
74
+ /**
75
+ * Child-side responder: on a trusted parent request, serialize this frame's
76
+ * DOM, cascade the request to this frame's own children while depth allows,
77
+ * and post the combined capture back to the requesting origin only.
78
+ */
79
+ export declare function startViewportSnapshotResponder({ targetWindow, takeSnapshot, measureFrameRect, isTrustedRequester, cascadeTimeoutMs, }: {
80
+ targetWindow: RelayWindow;
81
+ takeSnapshot: () => unknown;
82
+ measureFrameRect: (frameIndex: number) => ViewportFrameRect | null;
83
+ isTrustedRequester?: (origin: string) => boolean;
84
+ cascadeTimeoutMs?: number;
85
+ }): () => void;
86
+ export {};
@@ -0,0 +1 @@
1
+ export { VIEWPORT_SNAPSHOT_MAX_DEPTH, VIEWPORT_SNAPSHOT_REQUEST, VIEWPORT_SNAPSHOT_RESPONSE, isTrustedViewportSnapshotRequester, requestChildViewportSnapshots, startViewportSnapshotResponder } from '../../../chunk-RXYLMSNM.mjs';
@@ -0,0 +1,9 @@
1
+ import type { ViewportFrameRect } from "../lib/viewportSnapshot";
2
+ /** Relay frameIndex → on-screen rect; window.frames order is iframe document order. */
3
+ export declare function measureViewportFrameRect(frameIndex: number): ViewportFrameRect | null;
4
+ /**
5
+ * Answers a trusted parent frame's turn-end viewport-capture requests with an
6
+ * rrweb serialization of this frame's DOM, cascading into this frame's own
7
+ * iframes. Passive until asked; see docs/agent-session-viewport-filmstrip-prd.md.
8
+ */
9
+ export declare function useViewportSnapshotResponder(): void;