@full-self-browsing/phantom-stream 0.1.0 → 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.
Files changed (64) hide show
  1. package/README.md +48 -2
  2. package/dist/types/adapters/extension.d.ts.map +1 -1
  3. package/dist/types/adapters/playwright.d.ts.map +1 -1
  4. package/dist/types/capture/index.d.ts +150 -0
  5. package/dist/types/capture/index.d.ts.map +1 -1
  6. package/dist/types/index.d.ts +2 -0
  7. package/dist/types/player/index.d.ts +136 -0
  8. package/dist/types/player/index.d.ts.map +1 -0
  9. package/dist/types/protocol/constants.d.ts +22 -0
  10. package/dist/types/protocol/constants.d.ts.map +1 -1
  11. package/dist/types/protocol/index.d.ts +1 -0
  12. package/dist/types/protocol/media-reconcile.d.ts +53 -0
  13. package/dist/types/protocol/media-reconcile.d.ts.map +1 -0
  14. package/dist/types/protocol/messages.d.ts +326 -4
  15. package/dist/types/protocol/messages.d.ts.map +1 -1
  16. package/dist/types/recorder/index.d.ts +207 -0
  17. package/dist/types/recorder/index.d.ts.map +1 -0
  18. package/dist/types/renderer/asset-policy.d.ts +72 -0
  19. package/dist/types/renderer/asset-policy.d.ts.map +1 -0
  20. package/dist/types/renderer/diff.d.ts.map +1 -1
  21. package/dist/types/renderer/index.d.ts +61 -8
  22. package/dist/types/renderer/index.d.ts.map +1 -1
  23. package/dist/types/renderer/media-player.d.ts +114 -0
  24. package/dist/types/renderer/media-player.d.ts.map +1 -0
  25. package/dist/types/renderer/overlays.d.ts +12 -0
  26. package/dist/types/renderer/overlays.d.ts.map +1 -1
  27. package/dist/types/renderer/parser-safe.d.ts +26 -0
  28. package/dist/types/renderer/parser-safe.d.ts.map +1 -0
  29. package/dist/types/renderer/sanitize.d.ts +22 -0
  30. package/dist/types/renderer/sanitize.d.ts.map +1 -1
  31. package/dist/types/renderer/snapshot.d.ts +38 -0
  32. package/dist/types/renderer/snapshot.d.ts.map +1 -1
  33. package/dist/types/transport/websocket.d.ts.map +1 -1
  34. package/docs/ARCHITECTURE.md +83 -4
  35. package/docs/QUICKSTARTS.md +64 -0
  36. package/docs/SECURITY.md +279 -2
  37. package/docs/paper/OUTLINE.md +24 -91
  38. package/examples/bookmarklet-demo/viewer.html +12 -3
  39. package/examples/extension-mv3/viewer.html +10 -3
  40. package/package.json +25 -1
  41. package/src/adapters/extension.js +202 -7
  42. package/src/adapters/playwright-inject.js +645 -28
  43. package/src/adapters/playwright.js +176 -2
  44. package/src/capture/README.md +96 -1
  45. package/src/capture/index.js +1672 -40
  46. package/src/index.js +2 -0
  47. package/src/player/README.md +175 -0
  48. package/src/player/index.js +627 -0
  49. package/src/protocol/constants.js +24 -0
  50. package/src/protocol/index.js +1 -0
  51. package/src/protocol/media-reconcile.js +188 -0
  52. package/src/protocol/messages.js +195 -4
  53. package/src/recorder/README.md +225 -0
  54. package/src/recorder/index.js +487 -0
  55. package/src/renderer/README.md +111 -8
  56. package/src/renderer/asset-policy.js +172 -0
  57. package/src/renderer/diff.js +158 -15
  58. package/src/renderer/index.js +978 -21
  59. package/src/renderer/media-player.js +367 -0
  60. package/src/renderer/overlays.js +324 -0
  61. package/src/renderer/parser-safe.js +111 -0
  62. package/src/renderer/sanitize.js +25 -3
  63. package/src/renderer/snapshot.js +534 -3
  64. package/src/transport/websocket.js +36 -0
@@ -0,0 +1,72 @@
1
+ /**
2
+ * @typedef {Object} AssetOriginVerdict
3
+ * @property {boolean} allowed True only for a provably public https origin.
4
+ * @property {string} reason One of 'ok' | 'bad-scheme' | 'private-host'
5
+ * | 'unqualified-host' | 'parse-error'.
6
+ */
7
+ /**
8
+ * True when a (lowercased) hostname names a private, internal, loopback,
9
+ * link-local, or ULA address -- i.e. a host the viewer must never fetch from
10
+ * by default. Pure string/regex logic over the fixed, fully-enumerable
11
+ * denylist (RFC1918 + RFC3927 link-local + loopback + RFC4193 ULA + the
12
+ * mDNS .local suffix); a dependency-free hand-roll is preferred here over an
13
+ * IP library so the predicate stays Phase-15-reusable and table-testable.
14
+ *
15
+ * Bracketed IPv6 literals: WHATWG URL keeps the surrounding brackets on
16
+ * u.hostname (verified: new URL('https://[::1]/').hostname === '[::1]'), so
17
+ * the brackets are stripped here before the IPv6 checks match the bare
18
+ * address form. (.local is intentionally NOT handled here -- it is the
19
+ * unqualified-host branch's job in classifyAssetOrigin so a *.local name
20
+ * classifies as 'unqualified-host', not 'private-host'.)
21
+ *
22
+ * SELF-CONTAINED NORMALIZATION (Phase 12 review CR-01/WR-01): this predicate
23
+ * is an exported Phase-15-reusable seam, so it must NOT depend on the caller
24
+ * having pre-normalized the host through WHATWG `new URL()`. A single trailing
25
+ * dot (the FQDN root label -- 'localhost.', '127.0.0.1.') is stripped, the host
26
+ * is lowercased, and any IPv6 zone-id ('%eth0') is dropped here so a raw
27
+ * `Host:` header / CSS url() host / media URL host cannot bypass the deny
28
+ * decision. Beyond the IPv4 dotted-quad ranges this blocks IPv6 loopback
29
+ * (`::1`), the unspecified address (`::`), link-local fe80::/10, ULA fc00::/7,
30
+ * the NAT64 well-known prefix 64:ff9b::/96, and IPv4-mapped / IPv4-compatible
31
+ * IPv6 (`::ffff:a.b.c.d`, `::ffff:HHHH:HHHH`, `::a.b.c.d`) by extracting the
32
+ * embedded IPv4 and re-running the v4 ranges -- so the AWS/GCP/Azure metadata
33
+ * host 169.254.169.254 and 127.0.0.1 are blocked in every representation. The
34
+ * milestone has no use case for fetching from a raw IP literal, so this stays
35
+ * fail-closed: an IP-literal form it cannot confidently prove public is denied.
36
+ *
37
+ * @param {string} host Lowercased hostname (u.hostname) OR a raw host string.
38
+ * @returns {boolean}
39
+ */
40
+ export function isPrivateOrLocalHost(host: string): boolean;
41
+ /**
42
+ * Classify an asset URL for viewer-side fetch (MSEC-01). Fail-closed: every
43
+ * branch that is not "a provably public https host" returns allowed:false
44
+ * with a machine-readable reason. The reasons are stable identifiers the
45
+ * renderer maps to a dimensioned blocked-origin placeholder and that the
46
+ * asset-policy table test pins.
47
+ *
48
+ * parse failure -> { allowed:false, reason:'parse-error' }
49
+ * protocol !== 'https:' -> { allowed:false, reason:'bad-scheme' }
50
+ * private/internal/ULA host -> { allowed:false, reason:'private-host' }
51
+ * dotless or *.local host -> { allowed:false, reason:'unqualified-host' }
52
+ * otherwise -> { allowed:true, reason:'ok' }
53
+ *
54
+ * Note this is a FETCH gate, not an injection gate; http: is blocked here
55
+ * (mixed-content / no-TLS) even though hasDangerousScheme would allow it.
56
+ *
57
+ * @param {string} url Absolute asset URL (already absolutified by capture).
58
+ * @returns {AssetOriginVerdict}
59
+ */
60
+ export function classifyAssetOrigin(url: string): AssetOriginVerdict;
61
+ export type AssetOriginVerdict = {
62
+ /**
63
+ * True only for a provably public https origin.
64
+ */
65
+ allowed: boolean;
66
+ /**
67
+ * One of 'ok' | 'bad-scheme' | 'private-host'
68
+ * | 'unqualified-host' | 'parse-error'.
69
+ */
70
+ reason: string;
71
+ };
72
+ //# sourceMappingURL=asset-policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asset-policy.d.ts","sourceRoot":"","sources":["../../../src/renderer/asset-policy.js"],"names":[],"mappings":"AA+BA;;;;;GAKG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,2CAHW,MAAM,GACJ,OAAO,CA+DnB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,yCAHW,MAAM,GACJ,kBAAkB,CAoB9B;;;;;aA1Ia,OAAO;;;;;YACP,MAAM"}
@@ -1 +1 @@
1
- {"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../../src/renderer/diff.js"],"names":[],"mappings":"AAiEA;;;;GAIG;AAEH;;;;;;;;;;;GAWG;AAEH;;;;;;;;;;;;;GAaG;AACH,oCANW,QAAQ,aACR,KAAK,KAAQ,YACb,YAAY,SACZ,SAAS,GACP,IAAI,CAoShB;;;;;iBAjUa,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"}
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"}
@@ -1,3 +1,16 @@
1
+ /**
2
+ * The renderer's pre-write asset fetch gate (MSEC-01/MSEC-02). Pure: decides
3
+ * allow/deny for a single asset URL under the posture carried in ctx. Every
4
+ * branch that is not an explicit allow fails closed.
5
+ *
6
+ * @param {string} url Absolute asset URL about to be written into the mirror.
7
+ * @param {Object} [ctx] Posture: { mediaMode, allowAssetOrigins, assetOriginPolicy, kind }.
8
+ * @returns {{ allow: boolean, reason: string }}
9
+ */
10
+ export function gateAssetUrl(url: string, ctx?: any): {
11
+ allow: boolean;
12
+ reason: string;
13
+ };
1
14
  /**
2
15
  * The host-injected viewer transport. Mirrors the capture Transport's
3
16
  * fire-and-forget send contract and adds the receive side; Phase 4's
@@ -55,13 +68,32 @@
55
68
  * Hide the local node highlight. Idempotent.
56
69
  * @property {(nid: string|number, options?: {reason?: string}) => string|null} requestSubtree
57
70
  * Request a bounded fresh subtree for an indexed truncated marker. Returns
58
- * the generated requestId, or null when the nid is invalid, missing, or
59
- * 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).
60
74
  * @property {(kind: string, renderFn: (payload: *, anchorRect: ?Object, layer: Element) => void) => void} registerOverlay
61
75
  * Register a custom overlay kind (delegates to the overlays registry --
62
76
  * the host-facing extension seam from D-10).
63
- * @property {(eventName: 'state'|'health', handler: (event: Object) => void) => (() => void)} on
64
- * Subscribe to host-facing lifecycle and health events. Returns unsubscribe.
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
65
97
  */
66
98
  /**
67
99
  * Scale-to-fit math (pure). Port of dashboard.js:2859-2868 simplified to
@@ -190,8 +222,9 @@ export type ViewerHandle = {
190
222
  clearHighlight: () => void;
191
223
  /**
192
224
  * Request a bounded fresh subtree for an indexed truncated marker. Returns
193
- * the generated requestId, or null when the nid is invalid, missing, or
194
- * 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).
195
228
  */
196
229
  requestSubtree: (nid: string | number, options?: {
197
230
  reason?: string;
@@ -202,9 +235,29 @@ export type ViewerHandle = {
202
235
  */
203
236
  registerOverlay: (kind: string, renderFn: (payload: any, anchorRect: any | null, layer: Element) => void) => void;
204
237
  /**
205
- * Subscribe to host-facing lifecycle and health events. Returns unsubscribe.
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).
206
249
  */
207
- on: (eventName: "state" | "health", handler: (event: any) => void) => (() => void);
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;
208
261
  };
209
262
  export { escapeAttribute, buildShellAttributeString, buildSnapshotHtml, buildFramePlaceholderHtml } from "./snapshot.js";
210
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":"AA0CA;;;;;;;;;;;;;;;;GAgBG;AAEH;;;;;GAKG;AAEH;;;;;;;;;;;;;GAaG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH;;;;;;;;;;;;GAYG;AACH,oCANW,MAAM,SACN,MAAM,cACN,MAAM,cACN,MAAM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AAC,KAAK,KAAQ,KAAK,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC;;;;;;;oBAKxF,CAAC,OAAO,KAAQ,KAAK,IAAI;;;;;;;;;qBAczB,MAAM;gBACN,MAAM"}
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Create the parent-realm adaptive media player. The renderer injects the live
3
+ * deps in Plan 03; the Plan 02 tests inject stubs/fakes (a stub `win` carrying
4
+ * MediaSource, a controllable-canPlayType video stub, a fake playerFactory, and
5
+ * a `tryLazyImportHls` override). Maintains a per-nid registry so a re-snapshot
6
+ * (Plan 03) can destroyAll() before the new mirror document replaces the child
7
+ * elements (Pattern 2 -- player teardown on new identity).
8
+ *
9
+ * @param {MediaPlayerDeps} deps
10
+ * @returns {{
11
+ * attach: (videoEl: HTMLMediaElement, manifestUrl: string, ctx?: Object) => (Object|Promise<Object|undefined>|undefined),
12
+ * degrade: (nid: ?string, reason: string) => undefined,
13
+ * destroy: (nid: ?string) => undefined,
14
+ * destroyAll: () => undefined
15
+ * }}
16
+ */
17
+ export function createMediaPlayer(deps: MediaPlayerDeps): {
18
+ attach: (videoEl: HTMLMediaElement, manifestUrl: string, ctx?: any) => (any | Promise<any | undefined> | undefined);
19
+ degrade: (nid: string | null, reason: string) => undefined;
20
+ destroy: (nid: string | null) => undefined;
21
+ destroyAll: () => undefined;
22
+ };
23
+ export type PlayerAdapterCtx = {
24
+ /**
25
+ * iframe.contentDocument (where videoEl lives)
26
+ */
27
+ doc: Document;
28
+ /**
29
+ * gated, absolute manifest URL
30
+ */
31
+ manifestUrl: string;
32
+ /**
33
+ * derived from the manifest classifier
34
+ */
35
+ kind: "hls" | "dash";
36
+ /**
37
+ * the in-iframe child element
38
+ */
39
+ videoEl: HTMLMediaElement;
40
+ logger: any;
41
+ /**
42
+ * reuse Phase 12 gate
43
+ */
44
+ gateAsset: (url: string, kind: string) => {
45
+ allow: boolean;
46
+ };
47
+ /**
48
+ * element nid for overlay anchoring + the reason callback
49
+ */
50
+ nid: string | null;
51
+ };
52
+ export type PlayerAdapter = {
53
+ /**
54
+ * Bind the manifest to the element (host owns MSE/attachMedia/segment fetch in the PARENT realm).
55
+ */
56
+ attach: (videoEl: HTMLMediaElement, manifestUrl: string, ctx: PlayerAdapterCtx) => void;
57
+ /**
58
+ * Tear down: detach MSE, revoke object URLs, free buffers. Idempotent.
59
+ */
60
+ destroy: () => void;
61
+ /**
62
+ * Report a fatal/unrecoverable error with a reason code; the viewer degrades to poster.
63
+ */
64
+ onError?: (handler: (reason: string) => void) => void;
65
+ };
66
+ export type MediaPlayerDeps = {
67
+ /**
68
+ * iframe.contentDocument the child <video> lives in
69
+ */
70
+ doc: Document;
71
+ /**
72
+ * the PARENT realm window (MSE feature-detect surface)
73
+ */
74
+ win: Window;
75
+ /**
76
+ * Phase 12 fail-closed gate
77
+ */
78
+ gateAsset: (url: string, kind: string) => {
79
+ allow: boolean;
80
+ };
81
+ /**
82
+ * viewer logger (info/warn/error)
83
+ */
84
+ logger: any;
85
+ /**
86
+ * host-provided player seam
87
+ */
88
+ playerFactory?: (ctx: PlayerAdapterCtx) => PlayerAdapter;
89
+ /**
90
+ * degrade reason callback
91
+ */
92
+ onMediaUnavailable: (nid: string | null, reason: string) => void;
93
+ /**
94
+ * overlay driver
95
+ */
96
+ showOverlay: (kind: string, payload: any | null, ctx: any | null) => void;
97
+ /**
98
+ * anchor-rect resolver for the overlay
99
+ */
100
+ resolveNidRect: (nid: string | null) => any | null;
101
+ /**
102
+ * Phase 13 play kickoff
103
+ */
104
+ ensurePlaying: (videoEl: HTMLMediaElement, nid: string | null) => void;
105
+ /**
106
+ * keep/restore the element poster on degrade
107
+ */
108
+ keepPoster?: (nid: string | null) => void;
109
+ /**
110
+ * TEST SEAM: override the dynamic hls.js import
111
+ */
112
+ tryLazyImportHls?: () => Promise<any>;
113
+ };
114
+ //# sourceMappingURL=media-player.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media-player.d.ts","sourceRoot":"","sources":["../../../src/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GAAG,EAAG,MAAM,OAAA,KAAK,UAAO;;;;mBACzB,CAAC,OAAO,EAAE,gBAAgB,EAAE,GAAG,EAAG,MAAM,OAAA,KAAK,IAAI;;;;iBACjD,CAAC,GAAG,EAAG,MAAM,OAAA,KAAK,IAAI;;;;uBACtB,MAAM,OAAO,CAAC,GAAC,CAAC"}
@@ -81,6 +81,10 @@ export function mapHostPointToViewport(point: {
81
81
  * Dispatch one STREAM.OVERLAY payload through the registry.
82
82
  * @property {(payload: Object) => void} handleDialogMessage
83
83
  * STREAM.DIALOG handler (dialog card show/hide).
84
+ * @property {(kind: string, payload: ?Object, ctx?: {anchorRect?: ?Object}) => void} show
85
+ * Drive a registered overlay kind directly from renderer state (the media
86
+ * affordances are renderer-state-driven, not wire-driven; 13-UI-SPEC). ctx
87
+ * carries the pre-resolved anchorRect. A null payload hides (reset contract).
84
88
  * @property {() => void} resetOverlays
85
89
  * Hide all kinds (new-snapshot reset, dashboard.js:2762-2764 parity).
86
90
  */
@@ -158,6 +162,14 @@ export type OverlaysHandle = {
158
162
  * STREAM.DIALOG handler (dialog card show/hide).
159
163
  */
160
164
  handleDialogMessage: (payload: any) => void;
165
+ /**
166
+ * Drive a registered overlay kind directly from renderer state (the media
167
+ * affordances are renderer-state-driven, not wire-driven; 13-UI-SPEC). ctx
168
+ * carries the pre-resolved anchorRect. A null payload hides (reset contract).
169
+ */
170
+ show: (kind: string, payload: any | null, ctx?: {
171
+ anchorRect?: any | null;
172
+ }) => void;
161
173
  /**
162
174
  * Hide all kinds (new-snapshot reset, dashboard.js:2762-2764 parity).
163
175
  */
@@ -1 +1 @@
1
- {"version":3,"file":"overlays.d.ts","sourceRoot":"","sources":["../../../src/renderer/overlays.js"],"names":[],"mappings":"AA6JA;;;;;;;;;;;;;;;;;GAiBG;AACH,oCARW;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM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EAAE,MAAM,GAAC,IAAI,CAAA;CAAC,CA+B7D;AAED;;;;;;;;;GASG;AAEH;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH;;;;;;;;;GASG;AACH,qCANW;IAAC,QAAQ,EAAE,QAAQ,CAAC;IAAC,MAAM,CAAC,EAAE;QAAC,IAAI,WAAW;QAAC,IAAI,WAAW;QAAC,KAAK,WAAU;KAAC,CAAA;CAAC,GAI9E,cAAc,CAwe1B;AAnzBD;;;;;;;GAOG;AACH,iCA6Ka;;;;;;;;WAgHC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAC;;;;;;oBAE7C,CAAC,GAAG,EAAE,MAAM,GAAC,MAAM,KAAK,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAC,GAAC,IAAI,CAAC;;;;;;;;;;;WASzF,OAAO;;;;;cAIP,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE,GAAC,EAAE,UAAU,EAAE,UAAO,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,KAAK,IAAI;;;;0BAG3F,CAAC,OAAO,KAAQ,EAAE,GAAG,EAAE,cAAc,KAAK,IAAI;;;;yBAE9C,CAAC,OAAO,KAAQ,KAAK,IAAI;;;;;;UAEzB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,UAAO,EAAE,GAAG,CAAC,EAAE;QAAC,UAAU,CAAC,EAAE,UAAO,CAAA;KAAC,KAAK,IAAI;;;;mBAItE,MAAM,IAAI"}
@@ -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"}
@@ -1,3 +1,25 @@
1
+ /**
2
+ * Minimal srcset candidate parser for the URL+descriptor forms this project
3
+ * emits (mirror of the capture-side parser). Unlike split(','), it keeps
4
+ * commas inside a candidate URL attached to the URL token, so a benign
5
+ * candidate cannot turn into a bogus relative fetch candidate. Two carve-outs
6
+ * suppress the comma-as-separator split: (1) data:image URLs (a base64 comma /
7
+ * the data: mediatype comma), and (2) any scheme-bearing absolute URL
8
+ * (http(s)/etc.), because an unencoded comma in an http(s) query string would
9
+ * otherwise mis-split a legitimate responsive CDN URL into a bogus second
10
+ * candidate -- which then fails the fetch gate and over-blocks the whole <img>
11
+ * to a placeholder (review WR-02). This is a fidelity widening only; the gate
12
+ * decision per candidate is unchanged. Exported so the Phase-12 renderer fetch
13
+ * gates (diff ATTR branch, gateFragmentAssets, the snapshot string layer) gate
14
+ * srcset per-candidate through ONE parser and the attribute coverage cannot
15
+ * drift between sites (review WR-03/WR-04).
16
+ * @param {string} srcset
17
+ * @returns {{url: string, descriptor: string}[]}
18
+ */
19
+ export function parseSrcsetCandidates(srcset: string): {
20
+ url: string;
21
+ descriptor: string;
22
+ }[];
1
23
  /**
2
24
  * Targeted CSS value scrub -- the only string-operation pass in the render
3
25
  * pipeline, and it is a VALUE scrub (regex), never a parser. Same policy
@@ -1 +1 @@
1
- {"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../../src/renderer/sanitize.js"],"names":[],"mappings":"AAmJA;;;;;;;;;;;;;;;;;GAiBG;AACH,kCAHW,GAAC,GACC,MAAM,CA4BlB;AAED;;;;;;;;;GASG;AACH,wCAJW,GAAC,SACD,GAAC,GACC;IAAC,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,GAAC,IAAI,CAAA;CAAC,CAyB/C;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,uCANW,gBAAgB,GAAC,OAAO,GAAC,IAAI,aAC7B,gBAAgB,WAEhB;IAAC,IAAI,EAAE,IAAS,IAAI,EAAD,GAAC,EAAA,KAAG,IAAI,CAAA;CAAC,GAC1B,IAAI,CAyHhB;;;;;sBA9Ta,MAAM;;;;iBACN,MAAM;;;;qBACN,MAAM;;;;eACN,MAAM"}
1
+ {"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../../src/renderer/sanitize.js"],"names":[],"mappings":"AA+FA;;;;;;;;;;;;;;;;;GAiBG;AACH,8CAHW,MAAM,GACJ;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAC,EAAE,CA4B/C;AA8BD;;;;;;;;;;;;;;;;;GAiBG;AACH,kCAHW,GAAC,GACC,MAAM,CA4BlB;AAED;;;;;;;;;GASG;AACH,wCAJW,GAAC,SACD,GAAC,GACC;IAAC,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,GAAC,IAAI,CAAA;CAAC,CAyB/C;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,uCANW,gBAAgB,GAAC,OAAO,GAAC,IAAI,aAC7B,gBAAgB,WAEhB;IAAC,IAAI,EAAE,IAAS,IAAI,EAAD,GAAC,EAAA,KAAG,IAAI,CAAA;CAAC,GAC1B,IAAI,CAyHhB;;;;;sBApVa,MAAM;;;;iBACN,MAAM;;;;qBACN,MAAM;;;;eACN,MAAM"}
@@ -1,3 +1,41 @@
1
+ /**
2
+ * Rewrite fetchable <img> assets in a raw snapshot HTML string against an
3
+ * injected pre-write fetch gate (MSEC-01) and apply the ASST-03 currentSrc
4
+ * pin. For each <img>:
5
+ * 1. currentSrc pin: if data-ps-currentsrc is present, the effective src
6
+ * becomes that value and srcset/sizes are neutralized (removed) so the
7
+ * cross-origin viewer's DPR cannot re-negotiate a different variant.
8
+ * 2. fetch gate: gate(effectiveSrc, 'image') and gate every srcset
9
+ * candidate; if blocked, the entire <img> is replaced by the dimensioned
10
+ * blocked-origin placeholder (or srcset is stripped when an allowed src
11
+ * remains) so the parser never sees a fetchable blocked URL.
12
+ * An <img> with no src/currentsrc/srcset is left untouched.
13
+ *
14
+ * QUOTE-AWARE TAG SCAN (review CR-02): every start tag is located with a
15
+ * quote-aware scanner (findTagEnd), NOT a `[^>]*` regex -- a `>` inside a
16
+ * quoted attribute value (`alt="a>b"`) does not terminate the tag, so a
17
+ * blocked `src` after such a `>` can no longer slip through unmodified. An
18
+ * opener whose tag end cannot be located (an unbalanced quote running to EOF)
19
+ * is FAILED CLOSED: it is replaced by the dimensioned placeholder rather than
20
+ * passed through, so a malformed shape can never emit a fetchable blocked URL.
21
+ * The gate is fail-closed by construction (createViewer's gateAssetUrl); a
22
+ * missing gate leaves the markup unchanged (no-op) so this stays a pure string
23
+ * transform.
24
+ *
25
+ * PHASE 13 MEDIA GENERALIZATION (MEDIA-01 / V12): the scan now covers <img>
26
+ * (src/srcset + currentSrc pin), <video> (src + poster), and <source> (src) in
27
+ * ONE left-to-right pass -- at each cursor it advances to the nearest of the
28
+ * three openers and gates that tag, so a blocked media URL is neutralized at
29
+ * the string layer BEFORE the srcdoc parser can prefetch it (13-RESEARCH
30
+ * Pitfall 5). Nesting (<source> inside <video>) is handled naturally: the
31
+ * openers are independent matches, so each is gated on its own.
32
+ * @param {string} html Raw payload.html (string layer, pre-srcdoc).
33
+ * @param {(url: string, kind: string) => { allow: boolean }} gate
34
+ * @returns {string}
35
+ */
36
+ export function gateSnapshotAssets(html: string, gate: (url: string, kind: string) => {
37
+ allow: boolean;
38
+ }): string;
1
39
  /**
2
40
  * Escape a value for inclusion inside a double-quoted HTML attribute.
3
41
  * Renamed port of escapePreviewAttribute (dashboard.js:2671-2677): null and
@@ -1 +1 @@
1
- {"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../../../src/renderer/snapshot.js"],"names":[],"mappings":"AA+FA;;;;;;;GAOG;AACH,uCAHW,GAAC,GACC,MAAM,CAQlB;AAED;;;;;;;;;;GAUG;AACH,iDAJW,MAAO,IAAI,GAAC,SAAS,aACrB,MAAM,GAAC,IAAI,GAAC,SAAS,GACnB,MAAM,CAiBlB;AAED;;;;;;;;;;;;;;;GAeG;AACH,2CAHW,eAAe,GACb,MAAM,CA+BlB;AAED,8DAeC;8BAjKa,OAAO,yBAAyB,EAAE,eAAe"}
1
+ {"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../../../src/renderer/snapshot.js"],"names":[],"mappings":"AAoaA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,yCAJW,MAAM,QACN,CAAC,GAAG,EAAE,MAAM,EAAE,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AoOH"}
1
+ {"version":3,"file":"websocket.d.ts","sourceRoot":"","sources":["../../../src/transport/websocket.js"],"names":[],"mappings":"AA8LA;;;;;;GAMG;AACH,4DAFa,OAAO,CAAC,MAAM,CAAC,CA4B3B;AAED;;;;;;GAMG;AACH,uCAJW,MAAM,GAAC,WAAW,GAAC,eAAe,GAAC,IAAI,kBAErC,OAAO,CAAC;IAAC,EAAE,EAAE,IAAI,CAAC;IAAC,GAAG,MAAQ;CAAC,GAAG;IAAC,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAC,CAAC,CAmDzE;AAgCD;;;;;;;;;;;;GAYG;AACH,wDATa;IACR,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,KAAQ,KAAK,IAAI,CAAC;IAC9C,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,SAAS,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,KAAQ,KAAK,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC;IAC9E,QAAQ,EAAE,CAAC,OAAO,EAAE,CAAC,MAAM,KAAQ,KAAK,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC;IAC9D,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,SAAS,EAAE,SAAY,CAAA;CACxB,CAwQH"}
@@ -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
@@ -266,8 +269,84 @@ explicit browser/security boundaries or intentional default-mode tradeoffs:
266
269
  object/embed/script-like subtrees, and hostile CSS before mirrored content is
267
270
  transported or inserted. This is still a framework-maintained blocklist, so the
268
271
  viewer iframe remains sandboxed without `allow-scripts` as defense in depth.
269
- 6. **Open shadow DOM and same-origin iframes resolved in standalone Phase 8.**
270
- Remaining limits are closed shadow roots, cross-origin iframe content,
271
- and `<video>`/`<audio>` media pixels/streams. Closed shadow roots and
272
- cross-origin iframe content are browser security boundaries; the framework
272
+ 6. **Open shadow DOM and same-origin iframes resolved in standalone Phase 8;
273
+ `<video>`/`<audio>` mirrored by reference across the v2.0 milestone.** Media
274
+ is no longer a blanket non-captured boundary: `<video>`/`<audio>` are now
275
+ mirrored **by reference** -- playback state from the snapshot baseline,
276
+ progressive (direct) playback, and best-effort adaptive (HLS/DASH) playback
277
+ driven from a parent-realm surface -- and the media bytes never cross the
278
+ relay. The residual media limits narrow to three cases: DRM/EME-protected
279
+ content, which is unshareable by design and degrades to a poster;
280
+ MSE/`blob:` media with no discoverable manifest, whose origin-local object
281
+ URL is dead at the viewer and degrades to a poster; and raw media
282
+ pixels/frames, which are out of scope because PhantomStream mirrors media
283
+ by reference, not by pixel. Closed shadow roots and cross-origin iframe
284
+ content remain the standing browser security boundaries; the framework
273
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).
@@ -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. |