@full-self-browsing/phantom-stream 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -13,11 +13,13 @@ PhantomStream mirrors a live browser tab to a remote viewer as structured DOM da
13
13
  ![Playwright](https://img.shields.io/badge/Playwright-2EAD33?style=for-the-badge&logo=playwright&logoColor=white)
14
14
  ![MIT License](https://img.shields.io/badge/License-MIT-3DA639?style=for-the-badge)
15
15
 
16
+ [![npm](https://img.shields.io/npm/v/@full-self-browsing/phantom-stream?style=for-the-badge&logo=npm&logoColor=white&color=CB3837)](https://www.npmjs.com/package/@full-self-browsing/phantom-stream)
16
17
  [![Stars](https://img.shields.io/github/stars/fullselfbrowsing/PhantomStream?style=for-the-badge&logo=github&logoColor=white&color=555555)](https://github.com/fullselfbrowsing/PhantomStream/stargazers)
17
18
  [![Issues](https://img.shields.io/github/issues/fullselfbrowsing/PhantomStream?style=for-the-badge&logo=github&logoColor=white&color=555555)](https://github.com/fullselfbrowsing/PhantomStream/issues)
18
19
  [![Last Commit](https://img.shields.io/github/last-commit/fullselfbrowsing/PhantomStream?style=for-the-badge&logo=github&logoColor=white&color=555555)](https://github.com/fullselfbrowsing/PhantomStream/commits/main)
20
+ [![Discussions](https://img.shields.io/github/discussions/fullselfbrowsing/PhantomStream?style=for-the-badge&logo=github&logoColor=white&color=555555)](https://github.com/fullselfbrowsing/PhantomStream/discussions)
19
21
 
20
- [The Problem](#the-problem) · [The Solution](#the-solution) · [Why DOM Streaming](#why-dom-streaming-instead-of-video) · [Architecture](#architecture) · [Features](#features) · [Tech Stack](#tech-stack) · [Getting Started](#getting-started) · [Quickstarts](docs/QUICKSTARTS.md) · [Documentation](#documentation) · [Roadmap](#roadmap)
22
+ [The Problem](#the-problem) · [The Solution](#the-solution) · [Why DOM Streaming](#why-dom-streaming-instead-of-video) · [Architecture](#architecture) · [Features](#features) · [Tech Stack](#tech-stack) · [Getting Started](#getting-started) · [Quickstarts](docs/QUICKSTARTS.md) · [Documentation](#documentation) · [Roadmap](#roadmap) · [Discussions](https://github.com/fullselfbrowsing/PhantomStream/discussions)
21
23
 
22
24
  </div>
23
25
 
@@ -88,6 +90,7 @@ Core mechanisms (see [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) for the full t
88
90
  - **Dual watchdogs.** A capture-side self-watchdog rescues a stuck mutation queue. A second host-side alarm survives service-worker eviction and requests a fresh snapshot if the stream strands silently.
89
91
  - **Session identity.** Every message carries a `streamSessionId` plus a `snapshotId`. The viewer rejects stale messages, so late diffs from a previous page can never corrupt the mirror.
90
92
  - **Side channels.** Scroll position, automation overlays (action glow, progress card), and native `alert` / `confirm` / `prompt` dialogs mirror alongside the DOM.
93
+ - **Media by reference.** Images, video, and audio resolve to absolute source URLs and load in the viewer's own browser, so only URLs and small playback-state messages cross the relay. Playback syncs through a drift-corrected reconciler driven cross-realm, adaptive HLS and DASH play through an optional lazy player, and any media that cannot be referenced degrades to a never-break poster. A fail-closed fetch gate (https-only, private-range deny, `mediaMode`, CSP, no-referrer) governs every viewer fetch.
91
94
 
92
95
  ---
93
96
 
@@ -107,6 +110,11 @@ Core mechanisms (see [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) for the full t
107
110
  | **Capture-side sanitization** | Serialization strips `on*` handlers, dangerous URL schemes, `srcdoc`, and `object` / `embed` subtrees on the wire clone only. The live page is never touched. |
108
111
  | **Privacy masking** | `blockSelector`, `maskTextSelector`, `maskInputs`, and custom mask functions redact sensitive content before it leaves the page, with passwords always masked. |
109
112
  | **Side-channel mirroring** | Scroll, automation overlays, and native dialogs stream alongside the DOM and render as host-document overlays above the mirror. |
113
+ | **Media by reference** | Images, video, and audio render in the viewer by loading the original source URL over the viewer's own network, so media bytes never cross the relay. Covers `img`, `srcset`, `picture`, `source`, SVG image, CSS background image, and video poster. |
114
+ | **Drift-corrected playback** | Video and audio play from the source URL, driven cross-realm from the parent so no player code runs in the sandbox. A pure reconciler holds small drift in tolerance, hard-seeks on large drift, and rejoins the live edge. |
115
+ | **Adaptive streaming with fallback** | HLS and DASH play through an optional lazy player, and adapters surface manifest URLs as opt-in hints. Media that cannot be referenced degrades to a poster with an observable reason, so the mirror never breaks. `hls.js` is an optional peer dependency, so the published module stays dependency-free. |
116
+ | **Fail-closed media fetch** | An https-only origin policy blocks private and internal ranges, a `mediaMode` switch gates playable sources, a string-layer gate runs before `srcdoc` parse, and a document-level no-referrer policy sends no credentials by default. |
117
+ | **Record and play back** | The recorder timestamps the capture stream into a portable JSON recording, with optional keyframe chunks for streaming upload. The player rebuilds any moment from the nearest snapshot, plays at 0.25x to 16x, skips idle gaps, and keeps the mirror inert. |
110
118
  | **Playwright adapter** | Drop the capture core into a Playwright or CDP page through a ready-made adapter, including authorized reverse remote control. |
111
119
  | **Pluggable transport** | Capture, viewer, and relay all talk through a small transport seam, so the same core runs over WebSocket, an in-page loopback channel, or any channel you supply. |
112
120
 
@@ -188,6 +196,39 @@ server.listen(8787);
188
196
 
189
197
  Clients join a room by passing `?room=<id>&role=source|viewer` on the connection URL. See `examples/two-tab-demo/server.js` for the full room and role wiring.
190
198
 
199
+ **Record a session and play it back** (the recorder is a capture transport, and the player replays a recording in an inert viewer):
200
+
201
+ ```js
202
+ import { createCapture } from '@full-self-browsing/phantom-stream/capture';
203
+ import { createRecorder } from '@full-self-browsing/phantom-stream/recorder';
204
+
205
+ const recorder = createRecorder();
206
+ const capture = createCapture({
207
+ transport: recorder.transport,
208
+ skipElement: (el) => el.id === 'my-own-overlay'
209
+ });
210
+
211
+ capture.start();
212
+ // ... later
213
+ capture.stop(); // flushes pending diffs and stamps the end time
214
+ const text = JSON.stringify(recorder.toRecording({ title: 'checkout run' }));
215
+ ```
216
+
217
+ ```js
218
+ import { createPlayer } from '@full-self-browsing/phantom-stream/player';
219
+
220
+ const player = createPlayer({
221
+ container: document.getElementById('replay'),
222
+ recording: JSON.parse(text)
223
+ });
224
+
225
+ await player.seek(0); // nothing renders until the first seek or play
226
+ player.play({ speed: 2 }); // 0.25x to 16x
227
+ player.on('marker', (m) => console.log(m.t, m.kind)); // host marks from recorder.mark()
228
+ ```
229
+
230
+ A recording holds page content, so configure masking before you record (see [docs/SECURITY.md](docs/SECURITY.md)). `src/recorder/README.md` covers keyframe chunks for streaming upload and recording while also streaming live.
231
+
191
232
  **Run the tests and demos** straight from the repository:
192
233
 
193
234
  ```bash
@@ -206,6 +247,8 @@ src/ The framework
206
247
  protocol/ Wire types, LZ envelope, shared constants, session identity
207
248
  capture/ Page-side snapshot + MutationObserver diff streaming
208
249
  renderer/ Viewer reconstruction: snapshot, diff apply, overlays
250
+ recorder/ Timestamped capture transport and the portable recording format
251
+ player/ Seekable, speed-controlled, inert playback through the viewer
209
252
  relay/ Transport-agnostic routing core + WebSocket backend
210
253
  transport/websocket.js Browser-compatible WebSocket transport for both ends
211
254
  adapters/ Playwright / CDP injection adapter
@@ -226,11 +269,12 @@ bin/phantom-stream.js CLI entry point for the demos
226
269
 
227
270
  | Document | What it covers |
228
271
  |---|---|
229
- | [docs/QUICKSTARTS.md](docs/QUICKSTARTS.md) | Installable package paths for embedded loopback, WebSocket demo, Playwright/CDP, extension MV3, bookmarklet, and CSSOM mode |
272
+ | [docs/QUICKSTARTS.md](docs/QUICKSTARTS.md) | Installable package paths for embedded loopback, WebSocket demo, Playwright/CDP, extension MV3, bookmarklet, CSSOM mode, and record and play back |
230
273
  | [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) | End-to-end technical description of the capture, transport, relay, and renderer pipeline, plus known limitations |
231
274
  | [docs/SECURITY.md](docs/SECURITY.md) | The embed security contract: threat model, sanitization, masking, CSP, and sandbox guarantees |
232
275
  | [docs/DESIGN-HISTORY.md](docs/DESIGN-HISTORY.md) | How the system evolved, what failed along the way, and why the current shape won |
233
276
  | [docs/RELEASE.md](docs/RELEASE.md) | Package validation and publish-gate checklist |
277
+ | [CHANGELOG.md](CHANGELOG.md) | Release notes for every published version |
234
278
  | [docs/paper/OUTLINE.md](docs/paper/OUTLINE.md) | Research paper structure and the evaluation plan against video and rrweb baselines |
235
279
 
236
280
  ---
@@ -247,6 +291,8 @@ bin/phantom-stream.js CLI entry point for the demos
247
291
  | Security pipeline: sanitization, sandbox, privacy masking | Shipped |
248
292
  | Reference demos: two-tab, Playwright, and embedded loopback | Shipped |
249
293
  | Fidelity completion: WeakMap identity, nodeIds sidecars, shadow DOM, same-origin iframes, subtree recovery, and CSSOM mode | Shipped |
294
+ | Asset and media streaming by reference: static assets, drift-corrected video and audio sync, adaptive HLS/DASH with fallback, and media security | Shipped |
295
+ | Record and playback: timestamped recorder with keyframe chunks and a seekable, inert player | Unreleased |
250
296
  | Evaluation harness: bandwidth, latency, and fidelity against WebRTC, CDP screencast, and rrweb | Planned |
251
297
  | Research paper draft | Planned |
252
298
 
@@ -1 +1 @@
1
- {"version":3,"file":"playwright.d.ts","sourceRoot":"","sources":["../../../src/adapters/playwright.js"],"names":[],"mappings":"AAyBA;;;;GAIG;AACH,yDAFa,MAAM,CAIlB;AA6BD;;;;;GAKG;AACH,2DAunBC"}
1
+ {"version":3,"file":"playwright.d.ts","sourceRoot":"","sources":["../../../src/adapters/playwright.js"],"names":[],"mappings":"AAyBA;;;;GAIG;AACH,yDAFa,MAAM,CAIlB;AA4CD;;;;;GAKG;AACH,2DAunBC"}
@@ -138,6 +138,23 @@ export function currentSrcDiffers(resolvedCurrentSrc: string, resolvedSrc: strin
138
138
  * raw URL). Stricter than maskTextFn: a thrown text mask falls back to the
139
139
  * asterisk default, but a thrown URL redactor blocks (a half-redacted URL
140
140
  * that the viewer then fetches is worse than no URL).
141
+ * @property {number} [messageLimitBytes]
142
+ * Optional (quick task 261202-jwf), default RELAY_PER_MESSAGE_LIMIT_BYTES
143
+ * (1 MiB). The largest wire message this capture emits, in UTF-8 bytes of
144
+ * the JSON payload: it governs the snapshot hard reset, single mutation
145
+ * diffs, mutation chunking and subtree responses. Only a positive finite
146
+ * number is accepted; any other value falls back to the default. Relay
147
+ * users keep the default, because the relay drops messages over 1 MiB;
148
+ * local recorders that never pass through a relay (FSB records with 8 MiB)
149
+ * may raise it.
150
+ * @property {number} [snapshotBudgetBytes]
151
+ * Optional (quick task 261202-jwf), default
152
+ * floor(messageLimitBytes * SNAPSHOT_BUDGET_FRACTION). The budget the
153
+ * snapshot truncation passes and sidecar pruning aim for, in UTF-8 wire
154
+ * bytes. Only a positive finite number is accepted; any other value falls
155
+ * back to the default. Clamped to at most messageLimitBytes. Relay users
156
+ * keep the default; local recorders may raise it (FSB records with 4 MiB)
157
+ * so large pages keep every stylesheet.
141
158
  */
142
159
  /**
143
160
  * @typedef {Object} CaptureHandle
@@ -325,6 +342,27 @@ export type CaptureOptions = {
325
342
  nid: string;
326
343
  kind: ("image" | "media");
327
344
  }) => (string | null);
345
+ /**
346
+ * Optional (quick task 261202-jwf), default RELAY_PER_MESSAGE_LIMIT_BYTES
347
+ * (1 MiB). The largest wire message this capture emits, in UTF-8 bytes of
348
+ * the JSON payload: it governs the snapshot hard reset, single mutation
349
+ * diffs, mutation chunking and subtree responses. Only a positive finite
350
+ * number is accepted; any other value falls back to the default. Relay
351
+ * users keep the default, because the relay drops messages over 1 MiB;
352
+ * local recorders that never pass through a relay (FSB records with 8 MiB)
353
+ * may raise it.
354
+ */
355
+ messageLimitBytes?: number;
356
+ /**
357
+ * Optional (quick task 261202-jwf), default
358
+ * floor(messageLimitBytes * SNAPSHOT_BUDGET_FRACTION). The budget the
359
+ * snapshot truncation passes and sidecar pruning aim for, in UTF-8 wire
360
+ * bytes. Only a positive finite number is accepted; any other value falls
361
+ * back to the default. Clamped to at most messageLimitBytes. Relay users
362
+ * keep the default; local recorders may raise it (FSB records with 4 MiB)
363
+ * so large pages keep every stylesheet.
364
+ */
365
+ snapshotBudgetBytes?: number;
328
366
  };
329
367
  export type CaptureHandle = {
330
368
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/capture/index.js"],"names":[],"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.js";
3
3
  export * from "./renderer/index.js";
4
4
  export * from "./relay/index.js";
5
5
  export * from "./transport/websocket.js";
6
+ export * from "./recorder/index.js";
7
+ export * from "./player/index.js";
6
8
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Create a player for one recording in a host container. Creation is
3
+ * synchronous and renders nothing: call seek() or play() to show a frame.
4
+ *
5
+ * @param {PlayerOptions} options
6
+ * @returns {PlayerHandle}
7
+ */
8
+ export function createPlayer(options: PlayerOptions): PlayerHandle;
9
+ /** Slowest playback speed (a quarter of recorded time). */
10
+ export const PLAYER_MIN_SPEED: 0.25;
11
+ /** Fastest playback speed (16 times recorded time). */
12
+ export const PLAYER_MAX_SPEED: 16;
13
+ export type PlayerOptions = {
14
+ /**
15
+ * Required. Host element the playback viewer is appended into. It must be
16
+ * connected to a document: the mirror only loads in a connected iframe.
17
+ * Otherwise the factory throws Error('player-container-required').
18
+ */
19
+ container: Element;
20
+ /**
21
+ * Required. A Recording (see the recorder module) or a bare array of
22
+ * RecordingEvent objects. Validated at creation; an invalid one throws
23
+ * Error('player-recording-invalid:' + reason).
24
+ */
25
+ recording: import("../recorder/index.js").Recording | import("../recorder/index.js").RecordingEvent[];
26
+ /**
27
+ * Optional. Defaults to a console-backed logger. Shared with the viewer.
28
+ */
29
+ logger?: {
30
+ info: Function;
31
+ warn: Function;
32
+ error: Function;
33
+ };
34
+ /**
35
+ * Optional construction-document fallback, passed to createViewer.
36
+ */
37
+ document?: Document;
38
+ /**
39
+ * Optional cap, in recording ms, on how long an idle gap plays. 0 (the
40
+ * default) plays every gap in full. Negative or non-finite values throw
41
+ * Error('player-skip-idle-invalid').
42
+ */
43
+ skipIdleMs?: number;
44
+ /**
45
+ * Optional. Default true: the mirror iframe gets the inert attribute,
46
+ * pointer-events none, and tabindex -1, so pointer and keyboard input
47
+ * never reach mirrored links or forms. Pass false only for trusted
48
+ * recordings.
49
+ */
50
+ inert?: boolean;
51
+ /**
52
+ * 'reference' (default), 'poster', or 'off'. Passed to createViewer, which
53
+ * throws Error('viewer-mediamode-invalid') for anything else.
54
+ */
55
+ mediaMode?: string;
56
+ /**
57
+ * Optional asset origin hook, passed to createViewer unchanged.
58
+ */
59
+ assetOriginPolicy?: Function;
60
+ /**
61
+ * Optional asset host allowlist, passed to createViewer unchanged.
62
+ */
63
+ allowAssetOrigins?: string[];
64
+ };
65
+ /**
66
+ * A host mark on the playback timeline: the recorded mark data plus its
67
+ * kind and its time in ms from the first event.
68
+ */
69
+ export type PlayerMarker = {
70
+ t: number;
71
+ kind: string;
72
+ } & {
73
+ [x: string]: any;
74
+ };
75
+ export type PlayerTimeEvent = {
76
+ /**
77
+ * Playback position in ms from the first event.
78
+ */
79
+ currentTime: number;
80
+ /**
81
+ * Recording length in ms.
82
+ */
83
+ duration: number;
84
+ };
85
+ export type PlayerStateEvent = {
86
+ state: "paused" | "playing" | "ended";
87
+ currentTime: number;
88
+ };
89
+ export type PlayerHandle = {
90
+ /**
91
+ * Show exactly the recorded state at ms (clamped to [0, duration]).
92
+ * Resolves once that state is applied, or once a newer seek supersedes
93
+ * this one.
94
+ */
95
+ seek: (ms: number) => Promise<void>;
96
+ /**
97
+ * Start the frame clock. Throws Error('player-speed-invalid')
98
+ * synchronously for a bad speed. From the end, restarts at 0.
99
+ */
100
+ play: (options?: {
101
+ speed?: number;
102
+ }) => Promise<void>;
103
+ pause: () => void;
104
+ /**
105
+ * Speed in [PLAYER_MIN_SPEED, PLAYER_MAX_SPEED]; otherwise throws
106
+ * Error('player-speed-invalid').
107
+ */
108
+ setSpeed: (speed: number) => void;
109
+ /**
110
+ * Read-only playback position in ms from the first event.
111
+ */
112
+ currentTime: number;
113
+ /**
114
+ * Read-only recording length in ms.
115
+ */
116
+ duration: number;
117
+ /**
118
+ * Read-only.
119
+ */
120
+ playing: boolean;
121
+ /**
122
+ * Fresh copies of every host mark, in timeline order.
123
+ */
124
+ markers: () => PlayerMarker[];
125
+ /**
126
+ * Subscribe to playback events. Returns unsubscribe. Only 'state' calls
127
+ * the handler immediately with the current value. Unknown names or
128
+ * non-function handlers throw Error('player-event-unsupported').
129
+ */
130
+ on: (eventName: "time" | "ended" | "marker" | "state" | "loaded", handler: (event: any) => void) => (() => void);
131
+ /**
132
+ * Stop playback, resolve waiting seeks, and remove the viewer. Idempotent.
133
+ */
134
+ destroy: () => void;
135
+ };
136
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/player/index.js"],"names":[],"mappings":"AA+HA;;;;;;GAMG;AACH,sCAHW,aAAa,GACX,YAAY,CA8exB;AA9lBD,2DAA2D;AAC3D,+BAAgC,IAAI,CAAC;AAErC,uDAAuD;AACvD,+BAAgC,EAAE,CAAC;;;;;;;eAOrB,OAAO;;;;;;eAIP,OAAO,sBAAsB,EAAE,SAAS,GAAC,OAAO,sBAAsB,EAAE,cAAc,EAAE;;;;aAIxF;QAAC,IAAI,WAAW;QAAC,IAAI,WAAW;QAAC,KAAK,WAAU;KAAC;;;;eAEjD,QAAQ;;;;;;iBAER,MAAM;;;;;;;YAIN,OAAO;;;;;gBAKP,MAAM;;;;;;;;wBAKN,MAAM,EAAE;;;;;;2BAQT;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAC,GAAG;QAAO,MAAM,GAAE,GAAC;CAAC;;;;;iBAK5C,MAAM;;;;cAEN,MAAM;;;WAMN,QAAQ,GAAC,SAAS,GAAC,OAAO;iBAC1B,MAAM;;;;;;;;UAKN,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC;;;;;UAI7B,CAAC,OAAO,CAAC,EAAE;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAC,KAAK,OAAO,CAAC,IAAI,CAAC;WAG7C,MAAM,IAAI;;;;;cACV,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI;;;;iBAGvB,MAAM;;;;cAEN,MAAM;;;;aAEN,OAAO;;;;aAEP,MAAM,YAAY,EAAE;;;;;;QAEpB,CAAC,SAAS,EAAE,MAAM,GAAC,OAAO,GAAC,QAAQ,GAAC,OAAO,GAAC,QAAQ,EAAE,OAAO,EAAE,CAAC,KAAK,KAAQ,KAAK,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC;;;;aAIvG,MAAM,IAAI"}
@@ -36,7 +36,7 @@
36
36
  /**
37
37
  * @typedef {Object} AddDiffOp
38
38
  * @property {'add'} op
39
- * @property {string} parentNid Parent node id in the current mirror
39
+ * @property {string} parentNid Parent node id in the current mirror, or BODY_NID for a direct child of the main <body>
40
40
  * @property {string} html Serialized subtree HTML, without framework identity attrs
41
41
  * @property {string|null} beforeNid Insert before this sibling nid, or append when null
42
42
  * @property {string[]} nodeIds Preorder ids for every serialized element in html
@@ -59,6 +59,8 @@
59
59
  * @property {string} kind Frame policy kind, e.g. 'same-origin' or 'cross-origin'
60
60
  * @property {string} [html] Serialized frame body HTML for accessible frames
61
61
  * @property {string[]} [nodeIds] Preorder ids for serialized frame elements
62
+ * @property {string} [htmlNid] Counter nid of the frame document <html> (empty string when unavailable)
63
+ * @property {string} [bodyNid] Counter nid of the frame document <body> (empty string when unavailable)
62
64
  * @property {string[]} [stylesheets] Absolutified stylesheet URLs
63
65
  * @property {string[]} [inlineStyles] Sanitized inline style blocks
64
66
  * @property {StyleSource[]} [styleSources] Scoped CSSOM sources for this frame document
@@ -179,6 +181,7 @@
179
181
  * @typedef {Object} SnapshotPayload
180
182
  * @property {string} html Serialized body innerHTML (style-inlined; framework identity-clean)
181
183
  * @property {string[]} nodeIds Preorder ids for every serialized element in html
184
+ * @property {string} [bodyNid] Reserved main <body> identity, always BODY_NID (absent on captures older than this fix)
182
185
  * @property {ShadowRootPayload[]} [shadowRoots] Open shadow roots keyed by host nid
183
186
  * @property {FramePayload[]} [frames] Frame sidecars keyed by iframe nid
184
187
  * @property {boolean} truncated True if the size budget forced subtree drops
@@ -302,6 +305,49 @@ export namespace DIFF_OP {
302
305
  * nodeIds sidecars instead of mutating observed page elements.
303
306
  */
304
307
  export const NID_ATTR: "data-fsb-nid";
308
+ /**
309
+ * Reserved identity for the MAIN document `<body>` (quick task 261127-u5c).
310
+ *
311
+ * The snapshot sidecar starts below `<body>`, so the body itself never gets a
312
+ * counter nid. This value is non-numeric, so it can never collide with the
313
+ * capture counter (which only ever yields `String(n)` for n >= 1), and it
314
+ * consumes no counter value, so nodeIds sidecars keep their exact numbering.
315
+ *
316
+ * - Carried on every main snapshot as SnapshotPayload.bodyNid.
317
+ * - The add-op parentNid for a direct child of the main `<body>` (toasts,
318
+ * modals, portals); beforeNid resolution is unchanged.
319
+ * - The attr-op nid for a `<body>` attribute change other than `style` (the
320
+ * snapshot shell bodyStyle owns the mirror body's style attribute).
321
+ * - Not returned by capture getNodeId, and not a subtree-request target: the
322
+ * body is a structural anchor for body-level diffs, not an addressable
323
+ * element.
324
+ *
325
+ * Same-origin frame documents keep their counter htmlNid/bodyNid
326
+ * (FramePayload); only the main document body uses this value.
327
+ */
328
+ export const BODY_NID: "body";
329
+ /**
330
+ * Parser-safe placeholder element and attribute (quick task 261202-jwf).
331
+ *
332
+ * A DOM built by scripts can hold nesting that HTML text cannot express: a
333
+ * `<button>` inside a `<button>`, an `<a>` inside an `<a>`, a `<div>` inside a
334
+ * `<p>`, a `<tr>` without a `<tbody>`, an `<img>` with children. Re-parsing the
335
+ * serialized HTML rewrites such a tree, which moves content and breaks the
336
+ * positional nodeIds pairing.
337
+ *
338
+ * - Capture renames each such element in its detached wire clone to
339
+ * `<ps-node>` (PARSER_SAFE_TAG), copying every attribute and setting
340
+ * PARSER_SAFE_TAG_ATTR to the lowercase original tag. Element order and
341
+ * count are unchanged, so nodeIds sidecars stay aligned. Capture strips
342
+ * PARSER_SAFE_TAG_ATTR from page-owned `<ps-node>` elements.
343
+ * - Viewers restore only an allowlist of tags (never script, iframe, object,
344
+ * embed, style, link, meta, base, html, head, body or frameset), right
345
+ * after each parse and before the post-parse scrub and identity pairing.
346
+ * - Viewers older than 0.3.0 render the placeholders as generic elements:
347
+ * structure and nid pairing stay intact, only the original tags are lost.
348
+ */
349
+ export const PARSER_SAFE_TAG: "ps-node";
350
+ export const PARSER_SAFE_TAG_ATTR: "data-ps-tag";
305
351
  export type StyleScope = {
306
352
  kind: "document" | "shadow" | "frame";
307
353
  /**
@@ -344,7 +390,7 @@ export type StyleSourceDiffOp = {
344
390
  export type AddDiffOp = {
345
391
  op: "add";
346
392
  /**
347
- * Parent node id in the current mirror
393
+ * Parent node id in the current mirror, or BODY_NID for a direct child of the main <body>
348
394
  */
349
395
  parentNid: string;
350
396
  /**
@@ -415,6 +461,14 @@ export type FramePayload = {
415
461
  * Preorder ids for serialized frame elements
416
462
  */
417
463
  nodeIds?: string[];
464
+ /**
465
+ * Counter nid of the frame document <html> (empty string when unavailable)
466
+ */
467
+ htmlNid?: string;
468
+ /**
469
+ * Counter nid of the frame document <body> (empty string when unavailable)
470
+ */
471
+ bodyNid?: string;
418
472
  /**
419
473
  * Absolutified stylesheet URLs
420
474
  */
@@ -696,6 +750,10 @@ export type SnapshotPayload = {
696
750
  * Preorder ids for every serialized element in html
697
751
  */
698
752
  nodeIds: string[];
753
+ /**
754
+ * Reserved main <body> identity, always BODY_NID (absent on captures older than this fix)
755
+ */
756
+ bodyNid?: string;
699
757
  /**
700
758
  * Open shadow roots keyed by host nid
701
759
  */
@@ -1 +1 @@
1
- {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../../src/protocol/messages.js"],"names":[],"mappings":"AA2FA;;;;;GAKG;AAEH;;;;;;;;;;;;GAYG;AAEH;;;;;;;GAOG;AAEH;;;;;;;GAOG;AAEH;;;;;;;;;GASG;AAEH;;;;;;;;;GASG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AAEH;;;;;;;;GAQG;AAEH;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH;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;;aACN,MAAM,EAAE;;;;cACR,MAAM;;;;kBACN,iBAAiB,EAAE;;;;aACnB,YAAY,EAAE;;;;eACd,OAAO;;;;wBACP,MAAM;;;;iBACN,MAAM,EAAE;;;;kBACR,MAAM,EAAE;;;;mBACR,WAAW,EAAE;;;;oBACb,aAAa;;;;;;;;;;;;eAGb,MAAM;;;;eACN,MAAM;aACN,MAAM;aACN,MAAM;mBACN,MAAM;oBACN,MAAM;eACN,MAAM;gBACN,MAAM;SACN,MAAM;WACN,MAAM;;;;qBACN,MAAM;;;;gBACN,MAAM;;;UAKN,OAAO,GAAC,SAAS,GAAC,QAAQ;WAC1B,MAAM,GAAC,QAAQ;cACf,MAAM;;;;mBACN,MAAM;;;;aACN,GAAC"}
@@ -0,0 +1,207 @@
1
+ /**
2
+ * Build a recording object from events (and optional bounds and meta).
3
+ * Never validates: pair it with validateRecording when the input is not
4
+ * the recorder's own output.
5
+ *
6
+ * Bounds default to the first and last event times (0 and 0 with no
7
+ * events); explicit finite startedAt/endedAt are kept as given.
8
+ *
9
+ * @param {{events?: RecordingEvent[], meta?: Object, startedAt?: number, endedAt?: number}} [options]
10
+ * @returns {Recording}
11
+ */
12
+ export function createRecording(options?: {
13
+ events?: RecordingEvent[];
14
+ meta?: any;
15
+ startedAt?: number;
16
+ endedAt?: number;
17
+ }): Recording;
18
+ /**
19
+ * Structural check of a recording. Never throws. Checks, in order: an
20
+ * object, the format, the version, finite bounds with startedAt not above
21
+ * endedAt, a non-array object meta, a non-empty events array, each event's
22
+ * shape, non-decreasing t, and at least one snapshot with string html.
23
+ * Reports the first fault only. It checks structure, not content: payloads
24
+ * still go through the viewer's sanitizers at playback.
25
+ *
26
+ * @param {*} rec
27
+ * @returns {RecordingValidation}
28
+ */
29
+ export function validateRecording(rec: any): RecordingValidation;
30
+ /**
31
+ * Create a recorder: a capture transport that timestamps every message into
32
+ * a portable recording.
33
+ *
34
+ * Retained mode (no onChunk) keeps every event; toRecording(meta) returns
35
+ * the full recording. Chunk mode (onChunk given) retains nothing: every
36
+ * snapshot opens a new keyframe chunk, and a chunk is emitted when it
37
+ * reaches chunkMaxEvents, before an event that would make it span more than
38
+ * chunkMaxMs, or on flush(). onChunk runs synchronously; the recorder
39
+ * updates its own state first, so a throwing onChunk propagates to the
40
+ * caller without corrupting the recorder (capture contains transport
41
+ * throws).
42
+ *
43
+ * @param {RecorderOptions} [options]
44
+ * @returns {Recorder}
45
+ */
46
+ export function createRecorder(options?: RecorderOptions): Recorder;
47
+ /** Recording format id carried in every recording. */
48
+ export const RECORDING_FORMAT: "phantomstream-recording/1";
49
+ /** Recording schema version carried in every recording. */
50
+ export const RECORDING_VERSION: 1;
51
+ /** Event type of host timeline marks. Never a wire message type. */
52
+ export const HOST_MARK_TYPE: "host:mark";
53
+ /**
54
+ * One recorded message: the recorder clock time in ms, the wire type (or
55
+ * HOST_MARK_TYPE), and the payload exactly as it was sent.
56
+ */
57
+ export type RecordingEvent = {
58
+ /**
59
+ * Recorder clock time in ms. Never decreases within a recording.
60
+ */
61
+ t: number;
62
+ /**
63
+ * A STREAM.* protocol string, or HOST_MARK_TYPE for host marks.
64
+ */
65
+ type: string;
66
+ /**
67
+ * The wire payload (same reference as sent), or the JSON-safe mark data
68
+ * with its `kind`.
69
+ */
70
+ payload: any;
71
+ };
72
+ /**
73
+ * A portable recording. JSON-safe whenever its payloads are (capture
74
+ * payloads and host marks always are).
75
+ */
76
+ export type Recording = {
77
+ /**
78
+ * Exactly RECORDING_FORMAT.
79
+ */
80
+ format: string;
81
+ /**
82
+ * Exactly RECORDING_VERSION.
83
+ */
84
+ version: number;
85
+ /**
86
+ * Recorder clock ms of the first event.
87
+ */
88
+ startedAt: number;
89
+ /**
90
+ * Recorder clock ms of the end of the recording (the last flush, never
91
+ * below the last event's t).
92
+ */
93
+ endedAt: number;
94
+ /**
95
+ * Host metadata, shallow-copied from toRecording(meta).
96
+ */
97
+ meta: any;
98
+ /**
99
+ * Non-decreasing t; at least one STREAM.SNAPSHOT for playback.
100
+ */
101
+ events: RecordingEvent[];
102
+ };
103
+ /**
104
+ * One chunk-mode upload unit. A chunk whose first event is a snapshot is a
105
+ * keyframe: playback can start from it without any earlier chunk.
106
+ */
107
+ export type RecordingChunk = {
108
+ /**
109
+ * 0-based chunk counter.
110
+ */
111
+ seq: number;
112
+ /**
113
+ * t of the first event in the chunk.
114
+ */
115
+ t0: number;
116
+ /**
117
+ * t of the last event in the chunk.
118
+ */
119
+ t1: number;
120
+ /**
121
+ * True when events[0] is a STREAM.SNAPSHOT.
122
+ */
123
+ keyframe: boolean;
124
+ /**
125
+ * At most one snapshot, and only at index 0.
126
+ */
127
+ events: RecordingEvent[];
128
+ };
129
+ export type RecorderOptions = {
130
+ /**
131
+ * Clock in ms. Defaults to Date.now(). A non-finite reading reuses the
132
+ * previous event time.
133
+ */
134
+ now?: () => number;
135
+ /**
136
+ * Enables chunk mode: events are not retained, and each finished chunk is
137
+ * handed to this callback synchronously.
138
+ */
139
+ onChunk?: (chunk: RecordingChunk) => void;
140
+ /**
141
+ * Positive integer. Chunk mode cuts a chunk once it holds this many
142
+ * events. Default 200.
143
+ */
144
+ chunkMaxEvents?: number;
145
+ /**
146
+ * Positive finite ms. Chunk mode cuts before an event that would make the
147
+ * chunk span more than this. Default 1000.
148
+ */
149
+ chunkMaxMs?: number;
150
+ /**
151
+ * Record STREAM.READY readiness pings too. Default false.
152
+ */
153
+ recordReady?: boolean;
154
+ };
155
+ /**
156
+ * Capture-compatible transport returned on the recorder handle.
157
+ */
158
+ export type RecorderTransport = {
159
+ /**
160
+ * Stamp and record one wire message.
161
+ */
162
+ send: (type: string, payload: any) => void;
163
+ /**
164
+ * Same function as Recorder.flush; capture.stop() calls it.
165
+ */
166
+ flush: () => void;
167
+ };
168
+ export type RecorderIdentity = {
169
+ streamSessionId: string;
170
+ snapshotId: number;
171
+ };
172
+ export type Recorder = {
173
+ /**
174
+ * Pass to createCapture({ transport }).
175
+ */
176
+ transport: RecorderTransport;
177
+ /**
178
+ * Record a JSON-safe host mark. Returns false (recording nothing) for an
179
+ * empty kind or data that cannot be serialized.
180
+ */
181
+ mark: (kind: string, data?: any) => boolean;
182
+ /**
183
+ * Record a STREAM.OVERLAY with the current identity stamped last. Returns
184
+ * false (recording nothing) before the first snapshot.
185
+ */
186
+ overlay: (payload: any) => boolean;
187
+ /**
188
+ * A copy of the latest snapshot identity, or null before the first one.
189
+ */
190
+ identity: () => (RecorderIdentity | null);
191
+ /**
192
+ * Mark the end time and, in chunk mode, emit the partial chunk.
193
+ */
194
+ flush: () => void;
195
+ /**
196
+ * The retained recording, or null in chunk mode.
197
+ */
198
+ toRecording: (meta?: any) => (Recording | null);
199
+ };
200
+ export type RecordingValidation = {
201
+ ok: boolean;
202
+ /**
203
+ * Lowercase kebab-case reason, present only when ok is false.
204
+ */
205
+ error?: string;
206
+ };
207
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/recorder/index.js"],"names":[],"mappings":"AAuLA;;;;;;;;;;GAUG;AACH,0CAHW;IAAC,MAAM,CAAC,EAAE,cAAc,EAAE,CAAC;IAAC,IAAI,CAAC,MAAS;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAC,GAC9E,SAAS,CAsBrB;AAED;;;;;;;;;;GAUG;AACH,uCAHW,GAAC,GACC,mBAAmB,CAsC/B;AAED;;;;;;;;;;;;;;;GAeG;AACH,yCAHW,eAAe,GACb,QAAQ,CA+MpB;AApdD,sDAAsD;AACtD,+BAAgC,2BAA2B,CAAC;AAE5D,2DAA2D;AAC3D,gCAAiC,CAAC,CAAC;AAEnC,oEAAoE;AACpE,6BAA8B,WAAW,CAAC;;;;;;;;;OAY5B,MAAM;;;;UAEN,MAAM;;;;;;;;;;;;;;;YAYN,MAAM;;;;aAEN,MAAM;;;;eAEN,MAAM;;;;;aAEN,MAAM;;;;;;;;YAKN,cAAc,E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