@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.
- package/README.md +48 -2
- package/dist/types/adapters/extension.d.ts.map +1 -1
- package/dist/types/adapters/playwright.d.ts.map +1 -1
- package/dist/types/capture/index.d.ts +150 -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/constants.d.ts +22 -0
- package/dist/types/protocol/constants.d.ts.map +1 -1
- package/dist/types/protocol/index.d.ts +1 -0
- package/dist/types/protocol/media-reconcile.d.ts +53 -0
- package/dist/types/protocol/media-reconcile.d.ts.map +1 -0
- package/dist/types/protocol/messages.d.ts +326 -4
- 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/asset-policy.d.ts +72 -0
- package/dist/types/renderer/asset-policy.d.ts.map +1 -0
- package/dist/types/renderer/diff.d.ts.map +1 -1
- package/dist/types/renderer/index.d.ts +61 -8
- package/dist/types/renderer/index.d.ts.map +1 -1
- package/dist/types/renderer/media-player.d.ts +114 -0
- package/dist/types/renderer/media-player.d.ts.map +1 -0
- package/dist/types/renderer/overlays.d.ts +12 -0
- package/dist/types/renderer/overlays.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/dist/types/renderer/sanitize.d.ts +22 -0
- package/dist/types/renderer/sanitize.d.ts.map +1 -1
- package/dist/types/renderer/snapshot.d.ts +38 -0
- package/dist/types/renderer/snapshot.d.ts.map +1 -1
- package/dist/types/transport/websocket.d.ts.map +1 -1
- package/docs/ARCHITECTURE.md +83 -4
- package/docs/QUICKSTARTS.md +64 -0
- package/docs/SECURITY.md +279 -2
- package/docs/paper/OUTLINE.md +24 -91
- package/examples/bookmarklet-demo/viewer.html +12 -3
- package/examples/extension-mv3/viewer.html +10 -3
- package/package.json +25 -1
- package/src/adapters/extension.js +202 -7
- package/src/adapters/playwright-inject.js +645 -28
- package/src/adapters/playwright.js +176 -2
- package/src/capture/README.md +96 -1
- package/src/capture/index.js +1672 -40
- package/src/index.js +2 -0
- package/src/player/README.md +175 -0
- package/src/player/index.js +627 -0
- package/src/protocol/constants.js +24 -0
- package/src/protocol/index.js +1 -0
- package/src/protocol/media-reconcile.js +188 -0
- package/src/protocol/messages.js +195 -4
- package/src/recorder/README.md +225 -0
- package/src/recorder/index.js +487 -0
- package/src/renderer/README.md +111 -8
- package/src/renderer/asset-policy.js +172 -0
- package/src/renderer/diff.js +158 -15
- package/src/renderer/index.js +978 -21
- package/src/renderer/media-player.js +367 -0
- package/src/renderer/overlays.js +324 -0
- package/src/renderer/parser-safe.js +111 -0
- package/src/renderer/sanitize.js +25 -3
- package/src/renderer/snapshot.js +534 -3
- package/src/transport/websocket.js +36 -0
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
REMOTE_CONTROL,
|
|
14
14
|
REMOTE_CONTROL_STATE,
|
|
15
15
|
STREAM,
|
|
16
|
+
classifyManifest,
|
|
16
17
|
createRemoteControlStateEvent,
|
|
17
18
|
isRemoteControlType,
|
|
18
19
|
validateRemoteControlMessage,
|
|
@@ -49,13 +50,28 @@ function buildPlaywrightInjectSource(options) {
|
|
|
49
50
|
);
|
|
50
51
|
}
|
|
51
52
|
|
|
53
|
+
// Only JSON-safe, supported capture options reach the injected artifact:
|
|
54
|
+
// styleMode (first, when 'cssom'), then the quick task 261202-jwf budget
|
|
55
|
+
// options when each is a positive finite number. Anything else is dropped,
|
|
56
|
+
// so the defaults stay {}.
|
|
52
57
|
function normalizeCaptureOptions(options) {
|
|
53
58
|
var opts = options || {};
|
|
54
59
|
var captureOptions = opts.captureOptions || {};
|
|
60
|
+
var normalized = {};
|
|
55
61
|
if (captureOptions && captureOptions.styleMode === 'cssom') {
|
|
56
|
-
|
|
62
|
+
normalized.styleMode = 'cssom';
|
|
57
63
|
}
|
|
58
|
-
|
|
64
|
+
if (isPositiveFiniteNumber(captureOptions && captureOptions.messageLimitBytes)) {
|
|
65
|
+
normalized.messageLimitBytes = captureOptions.messageLimitBytes;
|
|
66
|
+
}
|
|
67
|
+
if (isPositiveFiniteNumber(captureOptions && captureOptions.snapshotBudgetBytes)) {
|
|
68
|
+
normalized.snapshotBudgetBytes = captureOptions.snapshotBudgetBytes;
|
|
69
|
+
}
|
|
70
|
+
return normalized;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function isPositiveFiniteNumber(value) {
|
|
74
|
+
return typeof value === 'number' && isFinite(value) && value > 0;
|
|
59
75
|
}
|
|
60
76
|
|
|
61
77
|
/**
|
|
@@ -87,6 +103,19 @@ export function createPlaywrightAdapter(options) {
|
|
|
87
103
|
error: function () {}
|
|
88
104
|
};
|
|
89
105
|
|
|
106
|
+
// Opt-in, off-by-default adaptive-manifest discovery (MADPT-02). When false/
|
|
107
|
+
// absent: register NO response listener and emit NO hints (graceful absence —
|
|
108
|
+
// the progressive path is untouched). The correlation hook is best-effort: it
|
|
109
|
+
// returns the nid of a single active opaque media element, or null/undefined
|
|
110
|
+
// for the always-safe page-scope default.
|
|
111
|
+
var discoverManifests = cfg.discoverManifests === true;
|
|
112
|
+
var resolveActiveMediaNid = typeof cfg.resolveActiveMediaNid === 'function'
|
|
113
|
+
? cfg.resolveActiveMediaNid
|
|
114
|
+
: function () { return null; };
|
|
115
|
+
// The hint is stamped with the same stream identity the adapter already
|
|
116
|
+
// forwards on STREAM messages, snooped from the bridge payloads it relays.
|
|
117
|
+
var currentIdentity = { streamSessionId: '', snapshotId: 0 };
|
|
118
|
+
|
|
90
119
|
var installed = false;
|
|
91
120
|
var disposed = false;
|
|
92
121
|
var cdpSession = cfg.cdpSession || null;
|
|
@@ -198,6 +227,7 @@ export function createPlaywrightAdapter(options) {
|
|
|
198
227
|
return { ok: false, error: 'bridge-type-invalid' };
|
|
199
228
|
}
|
|
200
229
|
try {
|
|
230
|
+
observeStreamIdentity(msg.payload);
|
|
201
231
|
transport.send(msg.type, msg.payload || {});
|
|
202
232
|
emit('bridge', { type: msg.type });
|
|
203
233
|
return { ok: true };
|
|
@@ -207,6 +237,138 @@ export function createPlaywrightAdapter(options) {
|
|
|
207
237
|
}
|
|
208
238
|
}
|
|
209
239
|
|
|
240
|
+
// Snoop the stream identity off the side-channel payloads the adapter relays,
|
|
241
|
+
// so an emitted media hint carries the same identity as the messages around
|
|
242
|
+
// it. Missing fields are ignored (the viewer's isCurrentStream accepts a hint
|
|
243
|
+
// with empty identity until a real stream identity has been observed).
|
|
244
|
+
function observeStreamIdentity(payload) {
|
|
245
|
+
if (!payload || Object(payload) !== payload) return;
|
|
246
|
+
if (typeof payload.streamSessionId === 'string' && payload.streamSessionId) {
|
|
247
|
+
currentIdentity.streamSessionId = payload.streamSessionId;
|
|
248
|
+
}
|
|
249
|
+
if (typeof payload.snapshotId === 'number' && Number.isFinite(payload.snapshotId)) {
|
|
250
|
+
currentIdentity.snapshotId = payload.snapshotId;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// Resolve the initiating frame of a Playwright Response, tolerant of API
|
|
255
|
+
// shape. Modern Playwright exposes response.frame() directly; older builds
|
|
256
|
+
// and the minimal test mock expose it via response.request().frame(). Returns
|
|
257
|
+
// null when no frame info is available so the caller degrades to "accept"
|
|
258
|
+
// (parity with isMainFrame(null) === true).
|
|
259
|
+
function responseFrame(response) {
|
|
260
|
+
try {
|
|
261
|
+
if (response && typeof response.frame === 'function') {
|
|
262
|
+
return response.frame() || null;
|
|
263
|
+
}
|
|
264
|
+
} catch (e) { /* fall through to the request() path */ }
|
|
265
|
+
try {
|
|
266
|
+
if (response && typeof response.request === 'function') {
|
|
267
|
+
var req = response.request();
|
|
268
|
+
if (req && typeof req.frame === 'function') return req.frame() || null;
|
|
269
|
+
}
|
|
270
|
+
} catch (e) { /* frame info unavailable */ }
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// Best-effort manifest observation. Reads the response url + content-type,
|
|
275
|
+
// classifies via the pure classifyManifest filter, and on a non-null kind
|
|
276
|
+
// emits STREAM.MEDIA_HINT through the same transport.send path the bridge
|
|
277
|
+
// uses. Fully contained: a hostile/odd response can never wedge the observer.
|
|
278
|
+
function handleManifestResponse(response) {
|
|
279
|
+
if (disposed || !discoverManifests) return;
|
|
280
|
+
try {
|
|
281
|
+
if (!response || typeof response.url !== 'function') return;
|
|
282
|
+
// Main-frame-only, parity with bindingCallback's isMainFrame check: a
|
|
283
|
+
// cross-origin sub-frame must not steer the top page's player. When frame
|
|
284
|
+
// info is unavailable, isMainFrame(null) === true (degrade to accept).
|
|
285
|
+
var frame = responseFrame(response);
|
|
286
|
+
if (frame && !isMainFrame(frame)) return;
|
|
287
|
+
var url = response.url();
|
|
288
|
+
var contentType = '';
|
|
289
|
+
if (typeof response.headers === 'function') {
|
|
290
|
+
var headers = response.headers() || {};
|
|
291
|
+
// Playwright lowercases header names; be tolerant of either casing.
|
|
292
|
+
contentType = headers['content-type'] || headers['Content-Type'] || '';
|
|
293
|
+
}
|
|
294
|
+
var kind = classifyManifest({ url: url, contentType: contentType });
|
|
295
|
+
if (!kind) return;
|
|
296
|
+
emitMediaHint(url, kind, contentType);
|
|
297
|
+
} catch (err) {
|
|
298
|
+
safeLog('warn', '[PlaywrightAdapter] manifest observe failed', { reason: 'manifest-observe-failed' });
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// The main frame's CDP frameId, learned opportunistically from
|
|
303
|
+
// Page.frameNavigated (the top-level frame has no parentId). Until known, the
|
|
304
|
+
// CDP manifest path degrades to "accept" (parity with the Playwright path when
|
|
305
|
+
// frame info is unavailable). Once known, a responseReceived carrying a
|
|
306
|
+
// different frameId is a sub-frame fetch and is ignored.
|
|
307
|
+
var mainCdpFrameId = null;
|
|
308
|
+
|
|
309
|
+
function observeCDPFrameNavigated(event) {
|
|
310
|
+
try {
|
|
311
|
+
var frame = event && event.frame;
|
|
312
|
+
if (!frame || typeof frame.id !== 'string') return;
|
|
313
|
+
// The top-level frame is the one without a parentId.
|
|
314
|
+
if (!frame.parentId) mainCdpFrameId = frame.id;
|
|
315
|
+
} catch (e) { /* contained -- frame tracking is best-effort */ }
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// CDP Network.responseReceived secondary path: { frameId, response: { url,
|
|
319
|
+
// headers, mimeType, frameId? } }. Same opt-in, same classifier, same
|
|
320
|
+
// emission as the page hook, with the analogous main-frame scope: drop a
|
|
321
|
+
// response whose CDP frameId is a known non-main frame.
|
|
322
|
+
function handleCDPResponseReceived(event) {
|
|
323
|
+
if (disposed || !discoverManifests) return;
|
|
324
|
+
try {
|
|
325
|
+
var resp = event && event.response;
|
|
326
|
+
if (!resp || typeof resp.url !== 'string') return;
|
|
327
|
+
// Main-frame-only when both ids are known. The frameId rides the event
|
|
328
|
+
// (and sometimes the response); accept when either is unknown.
|
|
329
|
+
if (mainCdpFrameId) {
|
|
330
|
+
var frameId = (event && typeof event.frameId === 'string') ? event.frameId
|
|
331
|
+
: (typeof resp.frameId === 'string' ? resp.frameId : null);
|
|
332
|
+
if (frameId && frameId !== mainCdpFrameId) return;
|
|
333
|
+
}
|
|
334
|
+
var headers = resp.headers || {};
|
|
335
|
+
var contentType = headers['content-type'] || headers['Content-Type']
|
|
336
|
+
|| (typeof resp.mimeType === 'string' ? resp.mimeType : '');
|
|
337
|
+
var kind = classifyManifest({ url: resp.url, contentType: contentType });
|
|
338
|
+
if (!kind) return;
|
|
339
|
+
emitMediaHint(resp.url, kind, contentType);
|
|
340
|
+
} catch (err) {
|
|
341
|
+
safeLog('warn', '[PlaywrightAdapter] cdp manifest observe failed', { reason: 'manifest-observe-failed' });
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function emitMediaHint(manifestUrl, kind, contentType) {
|
|
346
|
+
var payload = {
|
|
347
|
+
scope: 'page',
|
|
348
|
+
manifestUrl: manifestUrl,
|
|
349
|
+
kind: kind,
|
|
350
|
+
streamSessionId: currentIdentity.streamSessionId,
|
|
351
|
+
snapshotId: currentIdentity.snapshotId
|
|
352
|
+
};
|
|
353
|
+
if (contentType) payload.contentType = contentType;
|
|
354
|
+
var nid = null;
|
|
355
|
+
try {
|
|
356
|
+
nid = resolveActiveMediaNid();
|
|
357
|
+
} catch (err) {
|
|
358
|
+
nid = null; // correlation is best-effort; failure -> page scope
|
|
359
|
+
}
|
|
360
|
+
if (typeof nid === 'string' && nid) {
|
|
361
|
+
payload.scope = 'element';
|
|
362
|
+
payload.nid = nid;
|
|
363
|
+
}
|
|
364
|
+
try {
|
|
365
|
+
transport.send(STREAM.MEDIA_HINT, payload);
|
|
366
|
+
emit('mediahint', { kind: kind, scope: payload.scope });
|
|
367
|
+
} catch (err) {
|
|
368
|
+
safeLog('error', '[PlaywrightAdapter] media hint send failed', { reason: 'media-hint-send-failed' });
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
210
372
|
async function ensureCDPSession() {
|
|
211
373
|
if (cdpSession) return cdpSession;
|
|
212
374
|
if (typeof cfg.cdpSessionFactory !== 'function') return null;
|
|
@@ -305,6 +467,18 @@ export function createPlaywrightAdapter(options) {
|
|
|
305
467
|
addPageListener('domcontentloaded', function () { handleNavigation(null); });
|
|
306
468
|
addPageListener('load', function () { handleNavigation(null); });
|
|
307
469
|
|
|
470
|
+
// Opt-in manifest observation: only when discovery is enabled do we attach
|
|
471
|
+
// the 'response' listener (off by default -> no listener, graceful absence).
|
|
472
|
+
if (discoverManifests) {
|
|
473
|
+
addPageListener('response', handleManifestResponse);
|
|
474
|
+
if (session && typeof session.on === 'function') {
|
|
475
|
+
// CDP secondary path (same opt-in, same filter + emission). Track the
|
|
476
|
+
// main frame's CDP id so the response path can scope to it.
|
|
477
|
+
session.on('Page.frameNavigated', observeCDPFrameNavigated);
|
|
478
|
+
session.on('Network.responseReceived', handleCDPResponseReceived);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
308
482
|
if (transport && typeof transport.onMessage === 'function') {
|
|
309
483
|
unsubscribeTransport = transport.onMessage(function (type, payload) {
|
|
310
484
|
if (type === CONTROL.START) {
|
package/src/capture/README.md
CHANGED
|
@@ -39,6 +39,8 @@ const capture = createCapture({
|
|
|
39
39
|
| `maskTextFn` / `maskInputFn` | no | asterisk mask | Custom masking functions. They are fail-closed: thrown errors are logged and the default mask is used. |
|
|
40
40
|
| `styleMode` | no | `'computed'` | <code>'computed' | 'cssom'</code> — default mode preserves the legacy curated computed-style snapshot path. CSSOM mode omits generated computed inline styles and transports scoped `styleSources[]` plus `styleStrategy` instead. |
|
|
41
41
|
| `fetchStylesheet` | no | `null` | Optional synchronous hook used only by CSSOM mode when a stylesheet cannot expose readable `cssRules` and cannot be safely re-linked. Called as `fetchStylesheet({ href, scope, ownerKind })`; PhantomStream never performs hidden network fetches. |
|
|
42
|
+
| `messageLimitBytes` | no | `RELAY_PER_MESSAGE_LIMIT_BYTES` (1 MiB) | The largest wire message this capture emits, in UTF-8 bytes of the JSON payload. It governs the snapshot hard reset, single mutation diffs, mutation chunking, and subtree responses. Positive finite numbers only; any other value is ignored. Relay users keep the default, because the relay drops messages over 1 MiB. Local recorders that never send through a relay, such as FSB, pass a larger value (FSB uses 8 MiB). The Playwright adapter forwards it through `captureOptions`. |
|
|
43
|
+
| `snapshotBudgetBytes` | no | `floor(messageLimitBytes * 0.8)` | The budget the snapshot truncation passes and sidecar pruning aim for, in UTF-8 wire bytes, clamped to at most `messageLimitBytes`. Positive finite numbers only; any other value is ignored. Relay users keep the default. Local recorders pass a larger value so large pages keep every stylesheet (FSB uses 4 MiB). The Playwright adapter forwards it through `captureOptions`. |
|
|
42
44
|
|
|
43
45
|
A readiness ping (`STREAM.READY`) is emitted once, at factory creation
|
|
44
46
|
(divergence-ledger entry D3 — the reference pinged at script-load time).
|
|
@@ -100,6 +102,22 @@ const nid = capture.getNodeId(element);
|
|
|
100
102
|
non-elements, and disconnected elements. It is the capture-side bridge for
|
|
101
103
|
semantic addressing; it exposes identity only, never mirrored content.
|
|
102
104
|
|
|
105
|
+
The main document `<body>` itself never enters the `nodeIds` sidecar (the
|
|
106
|
+
serializer starts below it), so capture addresses it with the reserved
|
|
107
|
+
`BODY_NID` from the protocol module. Every main snapshot carries `bodyNid`
|
|
108
|
+
set to `BODY_NID`, a non-numeric value outside the nid counter, so `nodeIds`
|
|
109
|
+
numbering is unchanged. Elements appended or inserted directly under
|
|
110
|
+
`<body>` (toasts, modals, portals) stream as add ops with
|
|
111
|
+
`parentNid: BODY_NID`, with `beforeNid` resolved exactly as for any other
|
|
112
|
+
parent, and `<body>` attribute changes stream as attr ops on `BODY_NID`
|
|
113
|
+
except `style`: the snapshot's computed shell `bodyStyle` owns the mirror
|
|
114
|
+
body's style. Bare text directly under `<body>` still drops, because a text
|
|
115
|
+
op applies as `textContent =` and would flatten the whole mirror body.
|
|
116
|
+
`BODY_NID` is a structural anchor, not an addressable element:
|
|
117
|
+
`getNodeId(document.body)` stays `null`, and a subtree request for it is
|
|
118
|
+
answered content-free as `untracked`. Same-origin frame documents are
|
|
119
|
+
unchanged and keep their counter `htmlNid`/`bodyNid`.
|
|
120
|
+
|
|
103
121
|
## Phase 8 fidelity surfaces
|
|
104
122
|
|
|
105
123
|
Open shadow roots, same-origin iframes, live form values, late-added computed
|
|
@@ -179,6 +197,51 @@ add-op serialization policy: sanitized HTML, masking, URL absolutification,
|
|
|
179
197
|
curated styles, `nodeIds`, `shadowRoots[]`, and `frames[]`. Miss responses are
|
|
180
198
|
content-free and clear the request path without exposing page data.
|
|
181
199
|
|
|
200
|
+
### Parser-safe serialization
|
|
201
|
+
|
|
202
|
+
A DOM built by scripts can hold nesting that HTML text cannot express. Parsing
|
|
203
|
+
the serialized markup again rewrites it: a `<button>` inside a `<button>` closes
|
|
204
|
+
the outer one, an `<a>` inside an `<a>` is split, a `<div>` closes an open
|
|
205
|
+
`<p>`, and a bare `<tr>` gets an implied `<tbody>`. On x.com this moved the
|
|
206
|
+
sidebar column out of `<main>`, and every change of element count misaligned the
|
|
207
|
+
positional `nodeIds` pairing, so later ops hit the wrong nodes.
|
|
208
|
+
|
|
209
|
+
Capture therefore renames such elements in each detached wire clone to
|
|
210
|
+
`<ps-node data-ps-tag="original-tag">` placeholders (`PARSER_SAFE_TAG` and
|
|
211
|
+
`PARSER_SAFE_TAG_ATTR` in `src/protocol/messages.js`). A placeholder takes the
|
|
212
|
+
element's attributes, children, position and node id, so element order and
|
|
213
|
+
count stay the same and the sidecar stays aligned. The viewer restores the
|
|
214
|
+
original tags right after its parse. The rule families, applied to
|
|
215
|
+
HTML-namespace elements only (renaming too much is harmless):
|
|
216
|
+
|
|
217
|
+
- `button`, `a`, `form` or `nobr` inside an ancestor with the same tag;
|
|
218
|
+
- every `p` that contains a block element which would close it;
|
|
219
|
+
- a heading directly inside a heading;
|
|
220
|
+
- an `li` (or `dd`/`dt`) that reaches another `li` (or `dd`/`dt`) before a
|
|
221
|
+
special element other than `address`, `div` or `p`;
|
|
222
|
+
- `option`/`optgroup` inside an `option`, `optgroup` inside an `optgroup`, and
|
|
223
|
+
a `select` holding anything other than `option`, `optgroup`, `hr`, `script`
|
|
224
|
+
or `template`;
|
|
225
|
+
- `textarea`, `xmp` or `plaintext` with element children, and a void element
|
|
226
|
+
(`img`, `input`, `br`, `hr`, `wbr`, `area`, `col`, `source`, `track`) with
|
|
227
|
+
child nodes;
|
|
228
|
+
- a table the parser would restructure (renamed with all its table parts,
|
|
229
|
+
stopping at nested tables), and stray table parts whose parent cannot hold
|
|
230
|
+
them; the root of an add op or subtree response is exempt from the stray rule,
|
|
231
|
+
because the viewer's `<template>` parse accepts table parts there;
|
|
232
|
+
- `html`, `head`, `body` or `frameset` inside the clone.
|
|
233
|
+
|
|
234
|
+
`neutralizeParserHostileNesting` runs at all five serialization sites: the
|
|
235
|
+
`serializeDOM` body clone, shadow-root payloads, same-origin frame bodies,
|
|
236
|
+
add-op clones, and subtree responses (which reuse the add-op path). It runs
|
|
237
|
+
after each site's last `sanitizeForWire` call, so masking and the URL and
|
|
238
|
+
handler strips always see the original tags; it is a structural rename, never a
|
|
239
|
+
scrub. Capture also removes `data-ps-tag` from page-owned `<ps-node>` elements,
|
|
240
|
+
so a page cannot ask the viewer to create a tag. Viewers older than 0.3.0 show
|
|
241
|
+
the placeholders as generic elements: structure and node pairing stay intact,
|
|
242
|
+
only the original tag is lost. The inject bundle mirrors the pass, pinned by
|
|
243
|
+
`tests/inject-value-parity.test.js`.
|
|
244
|
+
|
|
182
245
|
## Phase 9 CSSOM style mode
|
|
183
246
|
|
|
184
247
|
`styleMode: 'computed' | 'cssom'` controls how visual style fidelity is
|
|
@@ -210,9 +273,25 @@ Stylesheet fallback reasons are explicit and wire-visible:
|
|
|
210
273
|
|
|
211
274
|
Live stylesheet changes stream as `DIFF_OP.STYLE_SOURCE` ops with
|
|
212
275
|
`action: 'upsert' | 'replace' | 'remove'`. The payload is scoped the same way
|
|
213
|
-
as snapshots.
|
|
276
|
+
as snapshots. Only sources that changed are sent: capture keeps a per-session
|
|
277
|
+
fingerprint of each source the viewer holds (owner kind, order, href, media,
|
|
278
|
+
disabled, plus the length and a 32-bit FNV-1a hash of the sanitized CSS text),
|
|
279
|
+
seeded from every emitted snapshot after budget pruning. A source whose
|
|
280
|
+
fingerprint matches is skipped, and a `remove` goes out only for a source the
|
|
281
|
+
viewer holds. `CSSStyleSheet.insertRule` / `deleteRule` / `replaceSync` are
|
|
214
282
|
patched while streaming in CSSOM mode; if a hook cannot be installed, capture
|
|
215
283
|
logs `cssom-hook-unavailable` and sends a fresh snapshot rather than guessing.
|
|
284
|
+
The patched methods cannot see rules the page adds from another JavaScript
|
|
285
|
+
world, such as page `insertRule` calls when capture runs in an extension's
|
|
286
|
+
isolated world. Each flush therefore compares a cheap per-scope signature
|
|
287
|
+
(sheet identity, `cssRules.length`, disabled, media and href for each
|
|
288
|
+
stylesheet) and re-collects a scope only when the signature changed. A full
|
|
289
|
+
re-collect runs at most every 2000 ms (`STYLE_FULL_RECONCILE_MS`) to catch
|
|
290
|
+
edits that keep the rule count; the fingerprints dedupe it, so it sends nothing
|
|
291
|
+
unless something changed. When a snapshot had to drop style sources to fit its
|
|
292
|
+
budget, the dropped sources go out as style-source ops in the next flush. A
|
|
293
|
+
style owner added after the snapshot reconciles the scope it lives in; capture
|
|
294
|
+
sends a fresh snapshot only when no known scope matches.
|
|
216
295
|
If a known style owner cannot be reconciled, the op carries
|
|
217
296
|
`cssom-style-source-stale` so the renderer can request recovery. Renderer-side
|
|
218
297
|
scope misses surface as `stale-style-scope`.
|
|
@@ -294,6 +373,22 @@ divergence, so it lives here rather than in the differential ledger):
|
|
|
294
373
|
snapshots and add ops. The observed page is no longer mutated for
|
|
295
374
|
framework identity, page-owned `data-fsb-nid` remains page data, and
|
|
296
375
|
`getNodeId(element) -> string|null` is the public live-element lookup.
|
|
376
|
+
- **E5 (quick task 261127-u5c, fidelity fix)** — body-level mutations: the
|
|
377
|
+
reference resolves add-op parents and attr targets through dataset nid
|
|
378
|
+
reads, and `<body>` never carries one, so elements appended directly to
|
|
379
|
+
the body (toasts, modals, portals) and attribute changes on the body were
|
|
380
|
+
dropped with no op, no stale miss, and no resync. Capture now addresses
|
|
381
|
+
the main body as the reserved `BODY_NID` (see "Node identity and semantic
|
|
382
|
+
addressing" above): direct body children emit add ops with
|
|
383
|
+
`parentNid: BODY_NID` (beforeNid resolution unchanged), and body attribute
|
|
384
|
+
changes emit attr ops on `BODY_NID` except `style`. Bare body text keeps
|
|
385
|
+
the drop, and frames are unchanged. Host UI placed directly under the body
|
|
386
|
+
now streams too, so same-page hosts exclude it with `skipElement`, exactly
|
|
387
|
+
as the viewer root already requires. Ledgered as **D28** in
|
|
388
|
+
`tests/differential/divergence-ledger.js`: `D28-body-level-mutations`
|
|
389
|
+
(mismatch, pinned by the `body-level-mutations` oracle scenario) and
|
|
390
|
+
`D28-body-nid-snapshot-key` (documented mapping for the new snapshot key),
|
|
391
|
+
and covered end-to-end in `tests/renderer-loopback.test.js`.
|
|
297
392
|
|
|
298
393
|
## Environment
|
|
299
394
|
|