@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 +48 -2
- package/dist/types/adapters/playwright.d.ts.map +1 -1
- package/dist/types/capture/index.d.ts +38 -0
- package/dist/types/capture/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/player/index.d.ts +136 -0
- package/dist/types/player/index.d.ts.map +1 -0
- package/dist/types/protocol/messages.d.ts +60 -2
- package/dist/types/protocol/messages.d.ts.map +1 -1
- package/dist/types/recorder/index.d.ts +207 -0
- package/dist/types/recorder/index.d.ts.map +1 -0
- package/dist/types/renderer/diff.d.ts.map +1 -1
- package/dist/types/renderer/index.d.ts +48 -8
- package/dist/types/renderer/index.d.ts.map +1 -1
- package/dist/types/renderer/parser-safe.d.ts +26 -0
- package/dist/types/renderer/parser-safe.d.ts.map +1 -0
- package/docs/ARCHITECTURE.md +70 -0
- package/docs/QUICKSTARTS.md +64 -0
- package/docs/SECURITY.md +46 -0
- package/docs/paper/OUTLINE.md +24 -91
- package/package.json +17 -1
- package/src/adapters/playwright-inject.js +596 -29
- package/src/adapters/playwright.js +17 -2
- package/src/capture/README.md +96 -1
- package/src/capture/index.js +602 -30
- package/src/index.js +2 -0
- package/src/player/README.md +175 -0
- package/src/player/index.js +627 -0
- package/src/protocol/messages.js +50 -2
- package/src/recorder/README.md +225 -0
- package/src/recorder/index.js +487 -0
- package/src/renderer/README.md +111 -8
- package/src/renderer/diff.js +57 -18
- package/src/renderer/index.js +129 -12
- package/src/renderer/parser-safe.js +111 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../../src/renderer/diff.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../../src/renderer/diff.js"],"names":[],"mappings":"AAsHA;;;;GAIG;AAEH;;;;;;;;;;;GAWG;AAEH;;;;;;;;;;;;;GAaG;AACH,oCANW,QAAQ,aACR,KAAK,KAAQ,YACb,YAAY,SACZ,SAAS,GACP,IAAI,CA8XhB;;;;;iBA3Za,MAAM;;;;mBACN,MAAM;;;;;;YAKN;QAAC,IAAI,EAAE,IAAS,IAAI,EAAD,GAAC,EAAA,KAAG,IAAI,CAAA;KAAC;;;;;mBAE5B,CAAS,IAAM,EAAN,MAAM,EAAE,IAAM,UAAG,IAAI;;;;;;uBAG9B,OAAO,eAAe,EAAE,gBAAgB"}
|
|
@@ -68,13 +68,32 @@ export function gateAssetUrl(url: string, ctx?: any): {
|
|
|
68
68
|
* Hide the local node highlight. Idempotent.
|
|
69
69
|
* @property {(nid: string|number, options?: {reason?: string}) => string|null} requestSubtree
|
|
70
70
|
* Request a bounded fresh subtree for an indexed truncated marker. Returns
|
|
71
|
-
* the generated requestId, or null when the nid is invalid, missing,
|
|
72
|
-
* already in flight
|
|
71
|
+
* the generated requestId, or null when the nid is invalid, missing,
|
|
72
|
+
* already in flight, or the reserved BODY_NID (the body is a structural
|
|
73
|
+
* anchor, not a recoverable subtree).
|
|
73
74
|
* @property {(kind: string, renderFn: (payload: *, anchorRect: ?Object, layer: Element) => void) => void} registerOverlay
|
|
74
75
|
* Register a custom overlay kind (delegates to the overlays registry --
|
|
75
76
|
* the host-facing extension seam from D-10).
|
|
76
|
-
* @property {(eventName: 'state'|'health', handler: (event: Object) => void) => (() => void)} on
|
|
77
|
-
* Subscribe to host-facing lifecycle and
|
|
77
|
+
* @property {(eventName: 'state'|'health'|'loaded', handler: (event: Object) => void) => (() => void)} on
|
|
78
|
+
* Subscribe to host-facing lifecycle, health, and loaded events. Returns
|
|
79
|
+
* unsubscribe. 'state' and 'health' call the handler immediately with the
|
|
80
|
+
* current value; 'loaded' never replays loads that happened before the
|
|
81
|
+
* subscription (see ViewerLoadedEvent).
|
|
82
|
+
* @property {(payload: Object) => void} handleSnapshot
|
|
83
|
+
* Host-driven snapshot entry point. Accepts a bare SnapshotPayload or a
|
|
84
|
+
* { type, payload } envelope and behaves exactly like the STREAM.SNAPSHOT
|
|
85
|
+
* dispatch target (identity adopted synchronously, mirror document loaded
|
|
86
|
+
* later; subscribe to 'loaded' to learn when it is ready).
|
|
87
|
+
*/
|
|
88
|
+
/**
|
|
89
|
+
* Payload of the viewer 'loaded' event: the stream identity active when a
|
|
90
|
+
* snapshot's mirror document finished loading. Fired after the viewer has
|
|
91
|
+
* flipped to streaming, once per loaded snapshot document, never for the
|
|
92
|
+
* bare about:blank load, and never replayed to late subscribers.
|
|
93
|
+
*
|
|
94
|
+
* @typedef {Object} ViewerLoadedEvent
|
|
95
|
+
* @property {string} streamSessionId
|
|
96
|
+
* @property {number} snapshotId
|
|
78
97
|
*/
|
|
79
98
|
/**
|
|
80
99
|
* Scale-to-fit math (pure). Port of dashboard.js:2859-2868 simplified to
|
|
@@ -203,8 +222,9 @@ export type ViewerHandle = {
|
|
|
203
222
|
clearHighlight: () => void;
|
|
204
223
|
/**
|
|
205
224
|
* Request a bounded fresh subtree for an indexed truncated marker. Returns
|
|
206
|
-
* the generated requestId, or null when the nid is invalid, missing,
|
|
207
|
-
* already in flight
|
|
225
|
+
* the generated requestId, or null when the nid is invalid, missing,
|
|
226
|
+
* already in flight, or the reserved BODY_NID (the body is a structural
|
|
227
|
+
* anchor, not a recoverable subtree).
|
|
208
228
|
*/
|
|
209
229
|
requestSubtree: (nid: string | number, options?: {
|
|
210
230
|
reason?: string;
|
|
@@ -215,9 +235,29 @@ export type ViewerHandle = {
|
|
|
215
235
|
*/
|
|
216
236
|
registerOverlay: (kind: string, renderFn: (payload: any, anchorRect: any | null, layer: Element) => void) => void;
|
|
217
237
|
/**
|
|
218
|
-
* Subscribe to host-facing lifecycle and
|
|
238
|
+
* Subscribe to host-facing lifecycle, health, and loaded events. Returns
|
|
239
|
+
* unsubscribe. 'state' and 'health' call the handler immediately with the
|
|
240
|
+
* current value; 'loaded' never replays loads that happened before the
|
|
241
|
+
* subscription (see ViewerLoadedEvent).
|
|
242
|
+
*/
|
|
243
|
+
on: (eventName: "state" | "health" | "loaded", handler: (event: any) => void) => (() => void);
|
|
244
|
+
/**
|
|
245
|
+
* Host-driven snapshot entry point. Accepts a bare SnapshotPayload or a
|
|
246
|
+
* { type, payload } envelope and behaves exactly like the STREAM.SNAPSHOT
|
|
247
|
+
* dispatch target (identity adopted synchronously, mirror document loaded
|
|
248
|
+
* later; subscribe to 'loaded' to learn when it is ready).
|
|
219
249
|
*/
|
|
220
|
-
|
|
250
|
+
handleSnapshot: (payload: any) => void;
|
|
251
|
+
};
|
|
252
|
+
/**
|
|
253
|
+
* Payload of the viewer 'loaded' event: the stream identity active when a
|
|
254
|
+
* snapshot's mirror document finished loading. Fired after the viewer has
|
|
255
|
+
* flipped to streaming, once per loaded snapshot document, never for the
|
|
256
|
+
* bare about:blank load, and never replayed to late subscribers.
|
|
257
|
+
*/
|
|
258
|
+
export type ViewerLoadedEvent = {
|
|
259
|
+
streamSessionId: string;
|
|
260
|
+
snapshotId: number;
|
|
221
261
|
};
|
|
222
262
|
export { escapeAttribute, buildShellAttributeString, buildSnapshotHtml, buildFramePlaceholderHtml } from "./snapshot.js";
|
|
223
263
|
export { createOverlays, mapRectToHost, mapHostPointToViewport, OVERLAY_CSS } from "./overlays.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/renderer/index.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/renderer/index.js"],"names":[],"mappings":"AA8GA;;;;;;;;GAQG;AACH,kCAJW,MAAM,cAEJ;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAsD9C;AAED;;;;;;;;;;;;;;;;GAgBG;AAEH;;;;;GAKG;AAEH;;;;;;;;;;;;;GAaG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH;;;;;;;;;GASG;AAEH;;;;;;;;;;;;GAYG;AACH,oCANW,MAAM,SACN,MAAM,cACN,MAAM,cACN,MAAM,GACJ;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAC,CAcvF;AAED;;;;;;;;;;;;GAYG;AACH,sCAHW,aAAa,GACX,YAAY,CAmgExB;;;;;;;;;;;;;UA3nEa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,KAAQ,KAAK,IAAI;;;;;eAGvC,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,KAAQ,KAAK,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC;;;;;eAGlE,CAAC,OAAO,EAAE,CAAC,MAAM,KAAQ,KAAK,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC;;;UAOnD,CAAC,GAAG,IAAI,EAAE,GAAC,KAAK,IAAI;UACpB,CAAC,GAAG,IAAI,EAAE,GAAC,KAAK,IAAI;WACpB,CAAC,GAAG,IAAI,EAAE,GAAC,KAAK,IAAI;;;;;;;eAKpB,OAAO;;;;;eAGP,eAAe;;;;aAGf,YAAY;;;;;wBAEZ,MAAM;;;;;;;YAON,MAAM,IAAI;;;;aAGV,MAAM,IAAI;;;;;wBAEV,MAAM;QAAC,KAAK,MAAS;QAAC,QAAQ,MAAS;QAAC,SAAS,MAAQ;KAAC;;;;;iBAG1D,CAAC,GAAG,EAAE,MAAM,GAAC,MAAM,KAAK,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,OAAO,CAAC;QAAC,IAAI,MAAS;QAAC,eAAe,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAC,GAAC,IAAI,CAAC;;;;;mBAGxH,CAAC,GAAG,EAAE,MAAM,GAAC,MAAM,EAAE,OAAO,CAAC,EAAE;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAC,KAAK,OAAO;;;;oBAG3D,MAAM,IAAI;;;;;;;oBAEV,CAAC,GAAG,EAAE,MAAM,GAAC,MAAM,EAAE,OAAO,CAAC,EAAE;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAC,KAAK,MAAM,GAAC,IAAI;;;;;qBAKhE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE,GAAC,EAAE,UAAU,EAAE,UAAO,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,KAAK,IAAI;;;;;;;QAG3F,CAAC,SAAS,EAAE,OAAO,GAAC,QAAQ,GAAC,QAAQ,EAAE,OAAO,EAAE,CAAC,KAAK,KAAQ,KAAK,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC;;;;;;;oBAKxF,CAAC,OAAO,KAAQ,KAAK,IAAI;;;;;;;;;qBAczB,MAAM;gBACN,MAAM"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Restore capture's parser-safe placeholders under root, in document order.
|
|
3
|
+
*
|
|
4
|
+
* Each `ps-node[data-ps-tag]` whose trimmed, lowercased tag is on the
|
|
5
|
+
* restorable allowlist becomes a real element created by root's owner
|
|
6
|
+
* document: every attribute except data-ps-tag is copied, the children are
|
|
7
|
+
* moved, and the element takes the placeholder's position. Placeholders for
|
|
8
|
+
* any other tag, and `ps-node` elements without data-ps-tag, are left as they
|
|
9
|
+
* are.
|
|
10
|
+
*
|
|
11
|
+
* Call it right after a parse and BEFORE sanitizeFragment and identity
|
|
12
|
+
* pairing. In a live document (the snapshot and frame mirrors) pass
|
|
13
|
+
* `options.filterUrl`: restored img, input, source and track elements then
|
|
14
|
+
* get their src / srcset / data-ps-currentsrc only through it, so a blocked
|
|
15
|
+
* URL is never set (and never fetched). Template content is inert and is
|
|
16
|
+
* gated before importNode instead.
|
|
17
|
+
*
|
|
18
|
+
* @param {ParentNode} root A parsed body, document or template content.
|
|
19
|
+
* @param {{ filterUrl?: (tag: string, attr: string, value: string) => (string|null) }} [options]
|
|
20
|
+
* filterUrl returns the value to set, or null to drop the attribute.
|
|
21
|
+
* @returns {number} How many placeholders were restored.
|
|
22
|
+
*/
|
|
23
|
+
export function restoreParserSafePlaceholders(root: ParentNode, options?: {
|
|
24
|
+
filterUrl?: (tag: string, attr: string, value: string) => (string | null);
|
|
25
|
+
}): number;
|
|
26
|
+
//# sourceMappingURL=parser-safe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser-safe.d.ts","sourceRoot":"","sources":["../../../src/renderer/parser-safe.js"],"names":[],"mappings":"AA2DA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,oDALW,UAAU,YACV;IAAE,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC,MAAM,GAAC,IAAI,CAAC,CAAA;CAAE,GAEzE,MAAM,CA+BlB"}
|
package/docs/ARCHITECTURE.md
CHANGED
|
@@ -108,6 +108,9 @@ matched to the page's paint cadence. `processMutationBatch` converts records to
|
|
|
108
108
|
| `style-source` | `action`, `sourceId`, `scope`, `source` | upsert, replace, or remove a scoped CSSOM source |
|
|
109
109
|
|
|
110
110
|
Mutations on untracked nodes (no nid) and on the host's own overlay are skipped.
|
|
111
|
+
The main `<body>` is addressed by the reserved `BODY_NID`, so direct body children and
|
|
112
|
+
body attribute changes other than `style` stream, while bare text directly under the
|
|
113
|
+
body still drops.
|
|
111
114
|
Open shadow roots and same-origin frame documents are observed explicitly, so
|
|
112
115
|
their mutations do not depend on `document.body` observer reachability.
|
|
113
116
|
Newly added subtrees carry curated computed styles in add-op HTML, collected in
|
|
@@ -280,3 +283,70 @@ explicit browser/security boundaries or intentional default-mode tradeoffs:
|
|
|
280
283
|
by reference, not by pixel. Closed shadow roots and cross-origin iframe
|
|
281
284
|
content remain the standing browser security boundaries; the framework
|
|
282
285
|
documents them as non-captured content rather than faking or bypassing them.
|
|
286
|
+
|
|
287
|
+
## 7. Record and playback
|
|
288
|
+
|
|
289
|
+
The standalone package adds after-the-fact playback on top of the same
|
|
290
|
+
pipeline. Capture is unchanged and the viewer gains only a `loaded` event: the
|
|
291
|
+
recorder sits where a live transport would, and the player sits where a relay
|
|
292
|
+
would.
|
|
293
|
+
|
|
294
|
+
- **The recorder is a capture transport** (`src/recorder/`). `createRecorder()`
|
|
295
|
+
returns `{ send, flush }` as `recorder.transport`, and capture sends into it
|
|
296
|
+
exactly what it would send to a live transport. Each message is stamped
|
|
297
|
+
`{ t, type, payload }` with `t = max(now(), previous t)`, so a recording is
|
|
298
|
+
the post-masking wire stream on a non-decreasing timeline. `STREAM.READY` is
|
|
299
|
+
dropped by default, `capture.stop()` calls `flush()` to stamp the end time,
|
|
300
|
+
and hosts add `host:mark` timeline entries and identity-stamped overlays.
|
|
301
|
+
The format is `phantomstream-recording/1`:
|
|
302
|
+
`{ format, version, startedAt, endedAt, meta, events }`, checked
|
|
303
|
+
structurally by `validateRecording`.
|
|
304
|
+
- **Keyframe-aligned chunks.** With `onChunk`, the recorder retains nothing:
|
|
305
|
+
every snapshot opens a new chunk, and chunks are also cut by event count,
|
|
306
|
+
by time span, or by `flush()`. A chunk that starts with a snapshot is a
|
|
307
|
+
keyframe, so storage can keep, drop, or fetch history in keyframe units, and
|
|
308
|
+
the concatenated chunk events rebuild the recording.
|
|
309
|
+
- **The player is `createViewer` behind a private transport** (`src/player/`).
|
|
310
|
+
It feeds recorded messages through the viewer's own dispatch, so playback
|
|
311
|
+
runs the same sanitizers, srcdoc CSP, sandbox, and asset gate as a live
|
|
312
|
+
stream, and the player writes no HTML itself.
|
|
313
|
+
- **Seek is a keyframe plus a forward apply.** A seek feeds the nearest
|
|
314
|
+
snapshot at or before the target (else the first), waits for the viewer's
|
|
315
|
+
`loaded` event, then applies every later event up to the target. The event
|
|
316
|
+
exists because a snapshot adopts its identity synchronously while its
|
|
317
|
+
document loads later, and the viewer drops mutations that arrive before that
|
|
318
|
+
load. At most one snapshot load is in flight: overlapping seeks resolve to
|
|
319
|
+
the last one, and a forward seek inside the loaded keyframe window applies
|
|
320
|
+
only the new events.
|
|
321
|
+
- **Play is a frame clock.** It advances by `requestAnimationFrame` time times
|
|
322
|
+
speed (0.25x to 16x), holds while a reached snapshot loads, and can cap idle
|
|
323
|
+
gaps with `skipIdleMs`. Host marks surface as `marker` events.
|
|
324
|
+
- **Overlay re-apply.** An anchored overlay is positioned when its message
|
|
325
|
+
arrives, so the player re-dispatches the latest overlay after each load and
|
|
326
|
+
each mutation batch. The agent highlight follows its element and hides once
|
|
327
|
+
that element is removed.
|
|
328
|
+
- **Media `sentAt` rebase.** Recorded `STREAM.MEDIA` payloads carry the capture
|
|
329
|
+
clock. The player rewrites `sentAt` onto the playback clock, on a copy, so
|
|
330
|
+
the drift reconciler expects the recorded media position at the playback
|
|
331
|
+
time.
|
|
332
|
+
- **Bounded resync.** The viewer's `CONTROL.START` resync request becomes a
|
|
333
|
+
forced re-seek of the current time, at most once per keyframe window until
|
|
334
|
+
the next host seek, so a drifting recording can never loop.
|
|
335
|
+
- **Inert mirror.** The playback iframe gets `inert`, `pointer-events: none`,
|
|
336
|
+
and `tabindex="-1"` by default, because a sandboxed srcdoc frame can still
|
|
337
|
+
navigate itself when a mirrored link is clicked.
|
|
338
|
+
|
|
339
|
+
Boundaries:
|
|
340
|
+
|
|
341
|
+
1. **Recorded subtree responses cannot replay.** `STREAM.SUBTREE_RESPONSE`
|
|
342
|
+
messages answer request ids that a fresh playback viewer never issued, so
|
|
343
|
+
the player skips them, and subtrees that were truncated at snapshot time
|
|
344
|
+
stay truncated in playback.
|
|
345
|
+
2. **Computed style mode freezes box sizes at snapshot time.** Drift
|
|
346
|
+
accumulates until the next snapshot. For long sessions prefer
|
|
347
|
+
`styleMode: 'cssom'`, or mint fresh keyframes with `capture.start()` at
|
|
348
|
+
quiet points, which also bounds seek cost.
|
|
349
|
+
3. **Assets load by reference at playback time.** Images and media may have
|
|
350
|
+
changed or expired since the recording was made, and fetching them reveals
|
|
351
|
+
the viewer's network identity to those origins (see `SECURITY.md`,
|
|
352
|
+
section 8).
|
package/docs/QUICKSTARTS.md
CHANGED
|
@@ -260,6 +260,69 @@ Fast check: if a stylesheet is blocked, inspect fallback reasons such as
|
|
|
260
260
|
`cssRules-blocked`, `href-relinked`, `adapter-fetch`, or `computed-fallback`.
|
|
261
261
|
PhantomStream never performs hidden network fetches.
|
|
262
262
|
|
|
263
|
+
## Record and Play Back
|
|
264
|
+
|
|
265
|
+
Use this when you want to review a session after the fact: scrub to any
|
|
266
|
+
moment, replay it at speed, and jump between agent actions, without touching
|
|
267
|
+
the original site again.
|
|
268
|
+
|
|
269
|
+
Prerequisites:
|
|
270
|
+
|
|
271
|
+
- A capture you already start and stop (any adapter or the embedded path).
|
|
272
|
+
- Somewhere to keep the recording JSON (a file, a database row, or object
|
|
273
|
+
storage).
|
|
274
|
+
- A container element attached to the document for playback.
|
|
275
|
+
|
|
276
|
+
Record on the capture side:
|
|
277
|
+
|
|
278
|
+
```js
|
|
279
|
+
import { createCapture } from '@full-self-browsing/phantom-stream/capture';
|
|
280
|
+
import { createRecorder } from '@full-self-browsing/phantom-stream/recorder';
|
|
281
|
+
|
|
282
|
+
const recorder = createRecorder();
|
|
283
|
+
const capture = createCapture({ transport: recorder.transport, maskInputs: true });
|
|
284
|
+
|
|
285
|
+
capture.start();
|
|
286
|
+
recorder.mark('action', { label: 'Click "Checkout"' });
|
|
287
|
+
// ...
|
|
288
|
+
capture.stop(); // stamps the recording's end time
|
|
289
|
+
await save(JSON.stringify(recorder.toRecording({ title: 'checkout run' })));
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
Play back on the viewer side:
|
|
293
|
+
|
|
294
|
+
```js
|
|
295
|
+
import { createPlayer } from '@full-self-browsing/phantom-stream/player';
|
|
296
|
+
|
|
297
|
+
const player = createPlayer({
|
|
298
|
+
container: document.getElementById('replay'),
|
|
299
|
+
recording: JSON.parse(await load()),
|
|
300
|
+
skipIdleMs: 1000
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
await player.seek(0);
|
|
304
|
+
player.on('marker', (m) => addChip(m.t, m.label)); // render labels with textContent
|
|
305
|
+
player.play({ speed: 4 });
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
For streaming upload, pass `onChunk` to `createRecorder` and store each
|
|
309
|
+
keyframe chunk; `src/recorder/README.md` shows how to rebuild a recording
|
|
310
|
+
from chunks and how to record while also streaming live.
|
|
311
|
+
|
|
312
|
+
Expected success signal: the mirror shows the first snapshot after
|
|
313
|
+
`seek(0)`, `play()` advances `currentTime` through the recording, and a
|
|
314
|
+
`marker` event fires for each `recorder.mark()`.
|
|
315
|
+
|
|
316
|
+
Fast check:
|
|
317
|
+
|
|
318
|
+
```js
|
|
319
|
+
import { validateRecording } from '@full-self-browsing/phantom-stream/recorder';
|
|
320
|
+
|
|
321
|
+
console.log(validateRecording(recording)); // { ok: true }
|
|
322
|
+
const last = player.markers().at(-1);
|
|
323
|
+
if (last) await player.seek(last.t); // the mirror shows that moment
|
|
324
|
+
```
|
|
325
|
+
|
|
263
326
|
## Security Checklist
|
|
264
327
|
|
|
265
328
|
Read [SECURITY.md](SECURITY.md) before embedding a viewer in a product.
|
|
@@ -287,3 +350,4 @@ match on a PhantomStream mirror iframe.
|
|
|
287
350
|
| Styles drift after class changes | Try `styleMode: 'cssom'` and inspect `styleStrategy.fallbacks`. |
|
|
288
351
|
| Bookmarklet fails silently | Listen for `phantomstream:bookmarklet-error` and check page CSP. |
|
|
289
352
|
| Private text appears in the mirror | Add `blockSelector`, `maskTextSelector`, or `maskInputs`; masking must happen capture-side. |
|
|
353
|
+
| Playback seek never resolves | Confirm the player container is attached to the document; the mirror only loads in a connected iframe. |
|
package/docs/SECURITY.md
CHANGED
|
@@ -26,6 +26,7 @@ while ensuring configured private content never leaves the captured page.
|
|
|
26
26
|
| Shadow root, same-origin frame, or subtree recovery HTML | New HTML insertion surface in the mirror | Same `sanitizeForWire` capture chokepoint, render-side `sanitizeFragment`, CSP meta, and no-`allow-scripts` sandbox |
|
|
27
27
|
| Cross-origin iframe content | Browser-origin data leakage | Capture never reads cross-origin iframe content; renderer shows content-free placeholders only |
|
|
28
28
|
| Live value diffs | Typed values bypass snapshot masking | `DIFF_OP.VALUE` payloads route through capture-side value masking before transport |
|
|
29
|
+
| Stored recordings replayed later | Page content at rest; hostile recording replay | Capture-side masking before recording; playback only through `createViewer`; inert playback mirror (section 8) |
|
|
29
30
|
| Future serialization path bypass | A new writer skips sanitization or masking | Static scan in `tests/security-chokepoint-purity.test.js` |
|
|
30
31
|
| New renderer `innerHTML` sink or sandbox weakening | Render-side defense bypass | InnerHTML allowlist and `allow-scripts` forbidden scan |
|
|
31
32
|
| Security contract rot | Docs stop matching shipped controls | `docs/SECURITY.md` marker guard in the purity test |
|
|
@@ -100,6 +101,21 @@ must mirror arbitrary real pages without breaking benign markup.
|
|
|
100
101
|
serialized and reparsed. String scrub/reparse is the mXSS anti-pattern this pipeline avoids.
|
|
101
102
|
- Strips and scrubs are counted and logged. They are never silent health events.
|
|
102
103
|
|
|
104
|
+
Parser-safe placeholders. Capture renames elements whose nesting HTML text cannot express (for
|
|
105
|
+
example a button inside a button) to `<ps-node data-ps-tag="original-tag">` in the detached wire
|
|
106
|
+
clone, after masking and the capture-side strips, and removes `data-ps-tag` from every page-owned
|
|
107
|
+
`<ps-node>`, so a page cannot ask the viewer to create a tag. The viewer restores a placeholder only
|
|
108
|
+
when its tag is on an allowlist: button, a, form, nobr, p, h1-h6, li, dd, dt, option, optgroup,
|
|
109
|
+
select, textarea, xmp, plaintext, img, input, br, hr, wbr, area, col, source, track, table, tbody,
|
|
110
|
+
thead, tfoot, tr, td, th, caption and colgroup. `script`, `iframe`, `object`, `embed`, `style`,
|
|
111
|
+
`link`, `meta`, `base`, `html`, `head`, `body` and `frameset` are never restored and stay inert
|
|
112
|
+
generic elements. The restore runs right after each parse and before the post-parse scrub and the
|
|
113
|
+
asset gate, so restored elements get the same `on*`, URL-scheme and fetch treatment as any other
|
|
114
|
+
element. In the live snapshot and frame documents, where a restored `<img>` would fetch as soon as
|
|
115
|
+
its `src` is set, `src`, `srcset` and `data-ps-currentsrc` on restored img, input, source and track
|
|
116
|
+
are passed through the viewer's asset gate first and dropped when blocked. Template parses are inert
|
|
117
|
+
and are gated before `importNode`. No new `innerHTML` sink exists for this.
|
|
118
|
+
|
|
103
119
|
## 4. Masking Guarantees
|
|
104
120
|
|
|
105
121
|
Masking is capture-side only. Masked content is transformed before transport and never appears
|
|
@@ -228,6 +244,8 @@ Hosts embedding PhantomStream must preserve these rules:
|
|
|
228
244
|
never move the asset fetch gate after the URL is written into the mirror (a post-write
|
|
229
245
|
gate is too late -- the browser has already issued the GET). Widen reachable origins
|
|
230
246
|
only through `allowAssetOrigins` / the `assetOriginPolicy` hook.
|
|
247
|
+
- Never replay a recording outside `createPlayer` or `createViewer`, and never set
|
|
248
|
+
`inert: false` on a player for recordings you do not trust.
|
|
231
249
|
|
|
232
250
|
## 6. Viewer-side resource fetching
|
|
233
251
|
|
|
@@ -385,3 +403,31 @@ Closed shadow roots, cross-origin iframe content, and media stream pixels remain
|
|
|
385
403
|
non-captured content. PhantomStream does not bypass those browser boundaries.
|
|
386
404
|
CSSOM mode is stylesheet capture only; it does not capture protected browser
|
|
387
405
|
content or weaken the sanitizer, CSP, or sandbox constraints.
|
|
406
|
+
|
|
407
|
+
## 8. Recordings and playback
|
|
408
|
+
|
|
409
|
+
The recorder (`src/recorder/`) stores a capture stream, and the player (`src/player/`) replays it
|
|
410
|
+
later through `createViewer`. Five rules apply:
|
|
411
|
+
|
|
412
|
+
1. **Recordings hold page content at rest.** A recording is the post-masking wire content: DOM
|
|
413
|
+
text, attribute values, unmasked form values, overlay labels, and host mark data. Masking
|
|
414
|
+
happens in capture, before a message reaches the recorder, so configure `blockSelector`,
|
|
415
|
+
`maskTextSelector`, and `maskInputs` before recording. Protect stored recordings like the live
|
|
416
|
+
stream: access control, retention limits, and encryption at rest.
|
|
417
|
+
2. **A recording is attacker-influenced input,** exactly like a live stream, and it may also have
|
|
418
|
+
been tampered with between recording and playback. The player writes no HTML: it routes every
|
|
419
|
+
payload through `createViewer`, so playback gets the same render sanitizers, srcdoc CSP, and
|
|
420
|
+
sandbox (exactly `allow-same-origin`) as a live mirror. `validateRecording` checks structure
|
|
421
|
+
only (format, version, bounds, event shape, time order, and a renderable snapshot); it is not
|
|
422
|
+
a content filter.
|
|
423
|
+
3. **The player is inert by default.** A sandboxed srcdoc frame runs no script, but it can still
|
|
424
|
+
navigate itself when a mirrored link is clicked. The player sets `inert`,
|
|
425
|
+
`pointer-events: none`, and `tabindex="-1"` on its mirror iframe, so pointer and keyboard
|
|
426
|
+
input never reach mirrored links or forms. `inert: false` is for trusted recordings only.
|
|
427
|
+
4. **The asset policy applies at playback time.** Images and media load by reference when the
|
|
428
|
+
recording is played, possibly long after it was made, through the same fail-closed gate
|
|
429
|
+
(section 6). For untrusted recordings use `mediaMode: 'poster'` or `mediaMode: 'off'`, or an
|
|
430
|
+
`assetOriginPolicy`. Playback reveals the viewer's network identity (address and timing) to
|
|
431
|
+
every asset origin the recording references.
|
|
432
|
+
5. **Host marks and overlay labels are data.** Render marker payloads and overlay labels with
|
|
433
|
+
`textContent`, never as HTML, as with dialog and overlay text everywhere else.
|
package/docs/paper/OUTLINE.md
CHANGED
|
@@ -1,100 +1,33 @@
|
|
|
1
|
-
# Paper
|
|
1
|
+
# Paper Draft — PhantomStream: DOM-Native Live Mirroring for Agentic Browsing
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Status: IEEE-style LaTeX draft exists in [`paper/main.tex`](../../paper/main.tex), with
|
|
4
|
+
measured local benchmark results generated from [`bench/results/local-latest.json`](../../bench/results/local-latest.json).
|
|
5
5
|
|
|
6
|
-
##
|
|
6
|
+
## Build
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
requires a live, trustworthy view of what it is doing — but video streaming is
|
|
10
|
-
bandwidth-heavy, semantically opaque (which element is the agent touching?), and awkward to
|
|
11
|
-
control through. We present PhantomStream, a DOM-native mirroring system that streams a
|
|
12
|
-
live tab as a style-inlined snapshot plus display-matched MutationObserver diffs addressed
|
|
13
|
-
by stable node identities, over a compressed, size-capped relay, reconstructed in a
|
|
14
|
-
sandboxed viewer with bidirectional control. Deployed inside an open-source browsing agent
|
|
15
|
-
(FSB), PhantomStream achieves [X]% lower bandwidth than WebRTC screen capture and [Y] ms
|
|
16
|
-
mirror latency while preserving element-level semantics that enable action highlighting and
|
|
17
|
-
click-through remote control. We report the reliability mechanisms — dual watchdogs,
|
|
18
|
-
session-identity staleness guards, budgeted truncation — that emerged from production
|
|
19
|
-
failures, and quantify the fidelity/bandwidth trade-offs of computed-style capture
|
|
20
|
-
strategies.
|
|
8
|
+
From the repository root:
|
|
21
9
|
|
|
22
|
-
|
|
10
|
+
```sh
|
|
11
|
+
npm run bench:local
|
|
12
|
+
npm run paper:check
|
|
13
|
+
```
|
|
23
14
|
|
|
24
|
-
|
|
25
|
-
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
1. A DOM-native live-mirroring architecture (snapshot + nid-addressed diffs +
|
|
29
|
-
side channels + reverse control path).
|
|
30
|
-
2. Reliability mechanisms for hostile runtime conditions (MV3 SW eviction, relay
|
|
31
|
-
message caps, slow/heavy pages) with production failure data.
|
|
32
|
-
3. An empirical comparison of style-capture strategies (full enumeration vs. curated
|
|
33
|
-
inlining vs. stylesheet-centric) on fidelity, payload size, and serialize latency.
|
|
34
|
-
4. Open-source framework + evaluation harness.
|
|
15
|
+
`npm run bench:local` runs the deterministic local corpus and refreshes
|
|
16
|
+
`paper/generated-results.tex`. `npm run paper:check` validates the benchmark result
|
|
17
|
+
shape, checks for unresolved placeholders, and builds `paper/main.pdf` through
|
|
18
|
+
`tectonic`.
|
|
35
19
|
|
|
36
|
-
##
|
|
20
|
+
## Current Draft Scope
|
|
37
21
|
|
|
38
|
-
-
|
|
39
|
-
|
|
40
|
-
-
|
|
41
|
-
-
|
|
42
|
-
|
|
43
|
-
single-writer mirror needs none of that.
|
|
44
|
-
- **Agent observability:** browser-use/agent frameworks' screenshot streams; computer-use
|
|
45
|
-
model viewers.
|
|
22
|
+
- Format: IEEE conference LaTeX, matching the Lattice paper style.
|
|
23
|
+
- Evaluation: deterministic local corpus with five pages and three activities.
|
|
24
|
+
- Baselines: PhantomStream, rrweb recorder/replay, and CDP PNG screencast.
|
|
25
|
+
- WebRTC: explicitly not claimed in this draft because headless Chromium does not provide
|
|
26
|
+
the same interactive `getDisplayMedia` permission surface as a real capture session.
|
|
46
27
|
|
|
47
|
-
##
|
|
28
|
+
## Next Paper Work
|
|
48
29
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
-
|
|
52
|
-
-
|
|
53
|
-
- 3.3 Style capture (the 45 s YouTube story; curated 85-prop list; default elision)
|
|
54
|
-
- 3.4 Diff pipeline (rAF batching = display-matched delivery)
|
|
55
|
-
- 3.5 Size budgeting (relay caps, 2-pass whole-subtree truncation, single-flush layout reads)
|
|
56
|
-
- 3.6 Transport (LZ envelope, session identity, staleness rejection)
|
|
57
|
-
- 3.7 Viewer (srcdoc reconstruction, scaling, layout modes, overlays, dialogs)
|
|
58
|
-
- 3.8 Reverse path (remote control coordinate reverse-mapping)
|
|
59
|
-
|
|
60
|
-
## 4. Reliability in production
|
|
61
|
-
|
|
62
|
-
The dual-watchdog design; MV3 service-worker eviction as an adversary; pending-intent
|
|
63
|
-
re-arm for the startup race; staleFlushCount telemetry. Frame as: "what a lab prototype
|
|
64
|
-
would not have needed, and a deployed system did" — supported by the inserted-phase
|
|
65
|
-
history (122.1–122.4, 211, 276).
|
|
66
|
-
|
|
67
|
-
## 5. Evaluation (planned)
|
|
68
|
-
|
|
69
|
-
- **Bandwidth:** PhantomStream vs. WebRTC screen capture vs. CDP screencast vs. rrweb
|
|
70
|
-
live-mode across a site corpus (static article, infinite scroll feed, SPA dashboard,
|
|
71
|
-
video-heavy page) and activity levels (idle, reading, agent-driven automation).
|
|
72
|
-
- **Latency:** mutation-to-mirror-paint time distribution; snapshot time vs. page weight.
|
|
73
|
-
- **Fidelity:** perceptual diff (SSIM / pixel-diff of mirror vs. real tab screenshots)
|
|
74
|
-
across Alexa/Tranco top-N pages; failure taxonomy (shadow DOM, canvas, video, iframes).
|
|
75
|
-
- **Style strategies ablation:** full-enumeration vs. curated-inlined vs.
|
|
76
|
-
stylesheet-centric capture on the three axes above.
|
|
77
|
-
- **Reliability:** watchdog rescue rates and stream-strand incidence from FSB telemetry
|
|
78
|
-
(if usable) or synthetic fault injection.
|
|
79
|
-
|
|
80
|
-
## 6. Discussion & limitations
|
|
81
|
-
|
|
82
|
-
Frozen-style drift; un-mirrored realms (shadow DOM, cross-origin iframes, media);
|
|
83
|
-
sanitization/security model of rendering attacker-influenced HTML in the viewer; privacy
|
|
84
|
-
of mirroring (the stream is the page content — implications and redaction hooks).
|
|
85
|
-
|
|
86
|
-
## 7. Future work
|
|
87
|
-
|
|
88
|
-
Stylesheet-centric capture; on-demand subtree fetch; multi-viewer fan-out; CRDT-free
|
|
89
|
-
multi-tab; integration as the standard observability layer for computer-use agents.
|
|
90
|
-
|
|
91
|
-
---
|
|
92
|
-
|
|
93
|
-
## TODO toward a draft
|
|
94
|
-
|
|
95
|
-
- [ ] Build the evaluation harness (`examples/` + a bench runner)
|
|
96
|
-
- [ ] Pick and freeze the site corpus
|
|
97
|
-
- [ ] Implement the stylesheet-centric capture variant (needed for the ablation)
|
|
98
|
-
- [ ] Pull watchdog/telemetry numbers from FSB if available
|
|
99
|
-
- [ ] Related-work deep dive: rrweb internals, Surfly patents, CDP screencast docs
|
|
100
|
-
- [ ] Decide venue + format (sets page budget)
|
|
30
|
+
- Add a public HAR record/replay corpus.
|
|
31
|
+
- Add a real WebRTC baseline with documented encoder and capture settings.
|
|
32
|
+
- Expand related work on co-browsing systems and agent-observability viewers.
|
|
33
|
+
- Turn the deterministic local benchmark into a CI performance-regression gate.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@full-self-browsing/phantom-stream",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "DOM-native live browser mirroring: snapshot + MutationObserver diff streaming with stable node identity, compressed transport, and bidirectional remote control.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -56,6 +56,16 @@
|
|
|
56
56
|
"import": "./src/renderer/index.js",
|
|
57
57
|
"default": "./src/renderer/index.js"
|
|
58
58
|
},
|
|
59
|
+
"./recorder": {
|
|
60
|
+
"types": "./dist/types/recorder/index.d.ts",
|
|
61
|
+
"import": "./src/recorder/index.js",
|
|
62
|
+
"default": "./src/recorder/index.js"
|
|
63
|
+
},
|
|
64
|
+
"./player": {
|
|
65
|
+
"types": "./dist/types/player/index.d.ts",
|
|
66
|
+
"import": "./src/player/index.js",
|
|
67
|
+
"default": "./src/player/index.js"
|
|
68
|
+
},
|
|
59
69
|
"./relay": {
|
|
60
70
|
"types": "./dist/types/relay/index.d.ts",
|
|
61
71
|
"import": "./src/relay/index.js",
|
|
@@ -75,6 +85,9 @@
|
|
|
75
85
|
"package:pack": "npm run types && npm pack --dry-run",
|
|
76
86
|
"package:smoke": "npm run types && node scripts/package-smoke.mjs",
|
|
77
87
|
"package:check": "npm test && npm run types && npm run lint:package && npm run attw && npm run package:pack && npm run package:smoke",
|
|
88
|
+
"bench:local": "node scripts/bench-local.mjs",
|
|
89
|
+
"paper:pdf": "cd paper && tectonic main.tex",
|
|
90
|
+
"paper:check": "node scripts/paper-check.mjs && npm run paper:pdf",
|
|
78
91
|
"demo": "node bin/phantom-stream.js demo",
|
|
79
92
|
"demo:playwright": "node bin/phantom-stream.js playwright-demo",
|
|
80
93
|
"example:loopback": "node examples/serve.js"
|
|
@@ -97,8 +110,11 @@
|
|
|
97
110
|
"devDependencies": {
|
|
98
111
|
"@arethetypeswrong/cli": "^0.18.3",
|
|
99
112
|
"jsdom": "^29.1.1",
|
|
113
|
+
"pixelmatch": "^7.2.0",
|
|
100
114
|
"playwright": "^1.60.0",
|
|
115
|
+
"pngjs": "^7.0.0",
|
|
101
116
|
"publint": "^0.3.21",
|
|
117
|
+
"rrweb": "^2.0.1",
|
|
102
118
|
"typescript": "^6.0.3"
|
|
103
119
|
},
|
|
104
120
|
"peerDependencies": {
|