@full-self-browsing/phantom-stream 0.1.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/LICENSE +21 -0
- package/README.md +263 -0
- package/bin/phantom-stream.js +193 -0
- package/dist/types/adapters/bookmarklet.d.ts +22 -0
- package/dist/types/adapters/bookmarklet.d.ts.map +1 -0
- package/dist/types/adapters/browser-inject.d.ts +7 -0
- package/dist/types/adapters/browser-inject.d.ts.map +1 -0
- package/dist/types/adapters/extension.d.ts +43 -0
- package/dist/types/adapters/extension.d.ts.map +1 -0
- package/dist/types/adapters/playwright-inject.d.ts +2 -0
- package/dist/types/adapters/playwright-inject.d.ts.map +1 -0
- package/dist/types/adapters/playwright.d.ts +14 -0
- package/dist/types/adapters/playwright.d.ts.map +1 -0
- package/dist/types/capture/index.d.ts +241 -0
- package/dist/types/capture/index.d.ts.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/protocol/constants.d.ts +35 -0
- package/dist/types/protocol/constants.d.ts.map +1 -0
- package/dist/types/protocol/envelope.d.ts +41 -0
- package/dist/types/protocol/envelope.d.ts.map +1 -0
- package/dist/types/protocol/index.d.ts +5 -0
- package/dist/types/protocol/index.d.ts.map +1 -0
- package/dist/types/protocol/messages.d.ts +520 -0
- package/dist/types/protocol/messages.d.ts.map +1 -0
- package/dist/types/protocol/remote-control.d.ts +70 -0
- package/dist/types/protocol/remote-control.d.ts.map +1 -0
- package/dist/types/relay/backends/ws.d.ts +39 -0
- package/dist/types/relay/backends/ws.d.ts.map +1 -0
- package/dist/types/relay/index.d.ts +4 -0
- package/dist/types/relay/index.d.ts.map +1 -0
- package/dist/types/relay/limits.d.ts +54 -0
- package/dist/types/relay/limits.d.ts.map +1 -0
- package/dist/types/relay/relay.d.ts +73 -0
- package/dist/types/relay/relay.d.ts.map +1 -0
- package/dist/types/renderer/diff.d.ts +62 -0
- package/dist/types/renderer/diff.d.ts.map +1 -0
- package/dist/types/renderer/index.d.ts +211 -0
- package/dist/types/renderer/index.d.ts.map +1 -0
- package/dist/types/renderer/overlays.d.ts +166 -0
- package/dist/types/renderer/overlays.d.ts.map +1 -0
- package/dist/types/renderer/sanitize.d.ts +73 -0
- package/dist/types/renderer/sanitize.d.ts.map +1 -0
- package/dist/types/renderer/snapshot.d.ts +41 -0
- package/dist/types/renderer/snapshot.d.ts.map +1 -0
- package/dist/types/transport/websocket.d.ts +44 -0
- package/dist/types/transport/websocket.d.ts.map +1 -0
- package/docs/ARCHITECTURE.md +273 -0
- package/docs/DESIGN-HISTORY.md +120 -0
- package/docs/QUICKSTARTS.md +289 -0
- package/docs/RELEASE.md +60 -0
- package/docs/SECURITY.md +156 -0
- package/docs/paper/OUTLINE.md +100 -0
- package/examples/bookmarklet-demo/demo.css +102 -0
- package/examples/bookmarklet-demo/server.js +297 -0
- package/examples/bookmarklet-demo/source.html +52 -0
- package/examples/bookmarklet-demo/viewer.html +48 -0
- package/examples/extension-mv3/demo.css +102 -0
- package/examples/extension-mv3/server.js +350 -0
- package/examples/extension-mv3/source.html +48 -0
- package/examples/extension-mv3/viewer.html +48 -0
- package/examples/loopback-mirror.html +369 -0
- package/examples/loopback-transport.js +65 -0
- package/examples/playwright-demo/demo.css +462 -0
- package/examples/playwright-demo/fixture.html +56 -0
- package/examples/playwright-demo/fixture.js +57 -0
- package/examples/playwright-demo/server.js +517 -0
- package/examples/playwright-demo/viewer.html +112 -0
- package/examples/playwright-demo/viewer.js +414 -0
- package/examples/serve.js +97 -0
- package/examples/two-tab-demo/demo.css +266 -0
- package/examples/two-tab-demo/server.js +233 -0
- package/examples/two-tab-demo/source.html +70 -0
- package/examples/two-tab-demo/source.js +213 -0
- package/examples/two-tab-demo/viewer.html +72 -0
- package/examples/two-tab-demo/viewer.js +121 -0
- package/package.json +107 -0
- package/src/adapters/bookmarklet.js +98 -0
- package/src/adapters/browser-inject.js +17 -0
- package/src/adapters/extension.js +322 -0
- package/src/adapters/playwright-inject.js +4401 -0
- package/src/adapters/playwright.js +540 -0
- package/src/capture/README.md +302 -0
- package/src/capture/index.js +4361 -0
- package/src/index.js +5 -0
- package/src/protocol/constants.js +49 -0
- package/src/protocol/envelope.js +75 -0
- package/src/protocol/index.js +4 -0
- package/src/protocol/messages.js +268 -0
- package/src/protocol/remote-control.js +300 -0
- package/src/relay/README.md +22 -0
- package/src/relay/backends/ws.js +186 -0
- package/src/relay/index.js +3 -0
- package/src/relay/limits.js +105 -0
- package/src/relay/relay.js +397 -0
- package/src/renderer/README.md +443 -0
- package/src/renderer/diff.js +389 -0
- package/src/renderer/index.js +1401 -0
- package/src/renderer/overlays.js +528 -0
- package/src/renderer/sanitize.js +366 -0
- package/src/renderer/snapshot.js +202 -0
- package/src/transport/websocket.js +553 -0
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
# PhantomStream Quickstarts
|
|
2
|
+
|
|
3
|
+
Use these paths when you want a live mirror quickly. They reuse the shipped
|
|
4
|
+
examples and package APIs instead of introducing a build step.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
Prerequisites:
|
|
9
|
+
|
|
10
|
+
- Node.js 20 or newer for local demos and package validation.
|
|
11
|
+
- A browser with WebSocket support for viewer/source pages.
|
|
12
|
+
- Playwright installed only when using the Playwright/CDP path.
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @full-self-browsing/phantom-stream
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Expected success signal: your project can import
|
|
19
|
+
`@full-self-browsing/phantom-stream/capture`,
|
|
20
|
+
`@full-self-browsing/phantom-stream/renderer`, and the other public subpaths.
|
|
21
|
+
|
|
22
|
+
Fast check:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
node --input-type=module -e "await import('@full-self-browsing/phantom-stream/capture')"
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Embedded Loopback
|
|
29
|
+
|
|
30
|
+
Use this when the source page and mirror live in the same first-party app.
|
|
31
|
+
There is no relay and no network transport.
|
|
32
|
+
|
|
33
|
+
Prerequisites:
|
|
34
|
+
|
|
35
|
+
- A page that can run first-party JavaScript modules.
|
|
36
|
+
- A container element for the mirror.
|
|
37
|
+
|
|
38
|
+
Minimal wiring:
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
import { CONTROL } from '@full-self-browsing/phantom-stream/protocol';
|
|
42
|
+
import { createCapture } from '@full-self-browsing/phantom-stream/capture';
|
|
43
|
+
import { createViewer } from '@full-self-browsing/phantom-stream/renderer';
|
|
44
|
+
|
|
45
|
+
function createLoopbackTransport() {
|
|
46
|
+
const toViewer = new Set();
|
|
47
|
+
const toCapture = new Set();
|
|
48
|
+
const fanOut = (handlers, type, payload) => {
|
|
49
|
+
queueMicrotask(() => handlers.forEach((handler) => handler(type, payload)));
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
captureTransport: { send: (type, payload) => fanOut(toViewer, type, payload) },
|
|
53
|
+
viewerTransport: {
|
|
54
|
+
send: (type, payload) => fanOut(toCapture, type, payload),
|
|
55
|
+
onMessage: (handler) => {
|
|
56
|
+
toViewer.add(handler);
|
|
57
|
+
return () => toViewer.delete(handler);
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
onControl: (handler) => {
|
|
61
|
+
toCapture.add(handler);
|
|
62
|
+
return () => toCapture.delete(handler);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const transport = createLoopbackTransport();
|
|
68
|
+
const viewer = createViewer({
|
|
69
|
+
container: document.getElementById('mirror'),
|
|
70
|
+
transport: transport.viewerTransport
|
|
71
|
+
});
|
|
72
|
+
const capture = createCapture({
|
|
73
|
+
transport: transport.captureTransport,
|
|
74
|
+
skipElement: (el) => !!el.closest('[data-phantomstream-host]')
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
transport.onControl((type) => {
|
|
78
|
+
if (type === CONTROL.START) capture.start();
|
|
79
|
+
});
|
|
80
|
+
capture.start();
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Expected success signal: the mirror iframe appears in the container and tracks
|
|
84
|
+
text or element changes in the same page.
|
|
85
|
+
|
|
86
|
+
Fast check: mark your host UI with `data-phantomstream-host` and verify it does
|
|
87
|
+
not recursively appear inside the mirror.
|
|
88
|
+
|
|
89
|
+
## WebSocket Two-Tab Demo
|
|
90
|
+
|
|
91
|
+
Use this when you want one browser tab mirrored into another through the
|
|
92
|
+
bundled relay.
|
|
93
|
+
|
|
94
|
+
Prerequisites:
|
|
95
|
+
|
|
96
|
+
- The package installed locally or available through `npx`.
|
|
97
|
+
- Two tabs in the same browser.
|
|
98
|
+
|
|
99
|
+
Command:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
npx @full-self-browsing/phantom-stream demo --no-open
|
|
103
|
+
# or, after local install:
|
|
104
|
+
phantom-stream demo --no-open
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Expected success signal: the command prints a source URL and a viewer URL. Open
|
|
108
|
+
both; DOM edits in the source tab appear in the viewer tab.
|
|
109
|
+
|
|
110
|
+
Fast check: the URLs must include the same `room` value and opposite
|
|
111
|
+
`role=source` / `role=viewer` values.
|
|
112
|
+
|
|
113
|
+
## Playwright/CDP
|
|
114
|
+
|
|
115
|
+
Use this when a script drives a real browser and you want a live viewer, with
|
|
116
|
+
optional consent-gated remote control.
|
|
117
|
+
|
|
118
|
+
Prerequisites:
|
|
119
|
+
|
|
120
|
+
- Playwright available in the host project.
|
|
121
|
+
- A relay URL with `role=source` for the driven page and `role=viewer` for the
|
|
122
|
+
viewer.
|
|
123
|
+
|
|
124
|
+
Demo command:
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
phantom-stream playwright-demo --no-open
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Minimal adapter wiring:
|
|
131
|
+
|
|
132
|
+
```js
|
|
133
|
+
import { chromium } from 'playwright';
|
|
134
|
+
import { createPlaywrightAdapter } from '@full-self-browsing/phantom-stream/adapters/playwright';
|
|
135
|
+
import { createWebSocketTransport } from '@full-self-browsing/phantom-stream/transport/websocket';
|
|
136
|
+
|
|
137
|
+
const browser = await chromium.launch();
|
|
138
|
+
const page = await browser.newPage();
|
|
139
|
+
const transport = createWebSocketTransport({
|
|
140
|
+
url: 'ws://127.0.0.1:8787/ws?room=demo&role=source',
|
|
141
|
+
role: 'source'
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const adapter = createPlaywrightAdapter({
|
|
145
|
+
page,
|
|
146
|
+
transport,
|
|
147
|
+
authorizeControl: async () => false
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
await adapter.install();
|
|
151
|
+
await page.goto('https://example.com');
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Expected success signal: the viewer receives a fresh snapshot after
|
|
155
|
+
navigation, and adapter state events remain locked unless your
|
|
156
|
+
`authorizeControl` hook approves a control action.
|
|
157
|
+
|
|
158
|
+
Fast check: run the demo first. If it works but your integration does not,
|
|
159
|
+
verify the page adapter is using the source relay URL and the viewer uses the
|
|
160
|
+
viewer relay URL.
|
|
161
|
+
|
|
162
|
+
## Extension MV3
|
|
163
|
+
|
|
164
|
+
Use this when capture runs from a Chromium MV3 extension service worker plus
|
|
165
|
+
content-script bridge.
|
|
166
|
+
|
|
167
|
+
Prerequisites:
|
|
168
|
+
|
|
169
|
+
- Chromium extension APIs: `runtime.onMessage`, `storage.session`, and
|
|
170
|
+
`alarms`.
|
|
171
|
+
- A content script that forwards page bridge messages to the service worker.
|
|
172
|
+
|
|
173
|
+
Demo command:
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
phantom-stream extension-demo --no-open
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Service-worker sketch:
|
|
180
|
+
|
|
181
|
+
```js
|
|
182
|
+
import { CONTROL } from '@full-self-browsing/phantom-stream/protocol';
|
|
183
|
+
import { createExtensionAdapter } from '@full-self-browsing/phantom-stream/adapters/extension';
|
|
184
|
+
import { createWebSocketTransport } from '@full-self-browsing/phantom-stream/transport/websocket';
|
|
185
|
+
|
|
186
|
+
const transport = createWebSocketTransport({
|
|
187
|
+
url: 'ws://127.0.0.1:8787/ws?room=demo&role=source',
|
|
188
|
+
role: 'source'
|
|
189
|
+
});
|
|
190
|
+
const adapter = createExtensionAdapter({ chrome, transport });
|
|
191
|
+
|
|
192
|
+
await adapter.install();
|
|
193
|
+
await adapter.sendControl(CONTROL.START, {
|
|
194
|
+
wsUrl: 'ws://127.0.0.1:8787/ws?room=demo&role=source',
|
|
195
|
+
roomKey: 'demo',
|
|
196
|
+
tabId
|
|
197
|
+
});
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Expected success signal: after the extension starts capture, service-worker
|
|
201
|
+
eviction recovery requests a fresh snapshot instead of depending on module
|
|
202
|
+
globals.
|
|
203
|
+
|
|
204
|
+
Fast check: confirm `chrome.storage.session` contains only stream intent
|
|
205
|
+
metadata, not mirrored page content.
|
|
206
|
+
|
|
207
|
+
## Bookmarklet
|
|
208
|
+
|
|
209
|
+
Use this when you want a no-extension loader for pages that permit bookmarklet
|
|
210
|
+
script injection. It does not bypass page CSP.
|
|
211
|
+
|
|
212
|
+
Prerequisites:
|
|
213
|
+
|
|
214
|
+
- A reachable HTTP(S) loader script URL.
|
|
215
|
+
- A relay source WebSocket URL.
|
|
216
|
+
|
|
217
|
+
Demo command:
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
phantom-stream bookmarklet-demo --no-open
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
Generate a bookmarklet string:
|
|
224
|
+
|
|
225
|
+
```js
|
|
226
|
+
import { createBookmarkletSource } from '@full-self-browsing/phantom-stream/adapters/bookmarklet';
|
|
227
|
+
|
|
228
|
+
const source = createBookmarkletSource({
|
|
229
|
+
scriptUrl: 'http://127.0.0.1:8787/bookmarklet/loader.js',
|
|
230
|
+
wsUrl: 'ws://127.0.0.1:8787/ws?room=demo&role=source',
|
|
231
|
+
roomKey: 'demo'
|
|
232
|
+
});
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Expected success signal: activating the bookmarklet injects the loader and the
|
|
236
|
+
connected viewer receives a snapshot.
|
|
237
|
+
|
|
238
|
+
Fast check: listen for `phantomstream:bookmarklet-error` on the page. A
|
|
239
|
+
`script-load-failed` reason usually means page policy blocked the loader.
|
|
240
|
+
|
|
241
|
+
## CSSOM Mode
|
|
242
|
+
|
|
243
|
+
Use CSSOM mode when stylesheet drift matters more than computed-inline
|
|
244
|
+
backward compatibility.
|
|
245
|
+
|
|
246
|
+
```js
|
|
247
|
+
import { createCapture } from '@full-self-browsing/phantom-stream/capture';
|
|
248
|
+
|
|
249
|
+
const capture = createCapture({
|
|
250
|
+
transport,
|
|
251
|
+
styleMode: 'cssom',
|
|
252
|
+
fetchStylesheet: ({ href }) => stylesheetCache.get(href) || null
|
|
253
|
+
});
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
Expected success signal: snapshots carry `styleSources[]` and `styleStrategy`,
|
|
257
|
+
and live stylesheet edits stream as `style-source` ops.
|
|
258
|
+
|
|
259
|
+
Fast check: if a stylesheet is blocked, inspect fallback reasons such as
|
|
260
|
+
`cssRules-blocked`, `href-relinked`, `adapter-fetch`, or `computed-fallback`.
|
|
261
|
+
PhantomStream never performs hidden network fetches.
|
|
262
|
+
|
|
263
|
+
## Security Checklist
|
|
264
|
+
|
|
265
|
+
Read [SECURITY.md](SECURITY.md) before embedding a viewer in a product.
|
|
266
|
+
|
|
267
|
+
- Do not add `allow-scripts` to the mirror iframe sandbox.
|
|
268
|
+
- Do not render wire payloads outside `createViewer`.
|
|
269
|
+
- Keep capture-side masking for private text and form values.
|
|
270
|
+
- Treat custom overlay and dialog text as text, not HTML.
|
|
271
|
+
- Keep relay logs and diagnostics content-free.
|
|
272
|
+
|
|
273
|
+
Expected success signal: mirrored content renders inside the PhantomStream
|
|
274
|
+
viewer iframe, sanitizer counters stay visible, and private content is masked
|
|
275
|
+
before transport.
|
|
276
|
+
|
|
277
|
+
Fast check: search your integration for `allow-scripts`; there should be no
|
|
278
|
+
match on a PhantomStream mirror iframe.
|
|
279
|
+
|
|
280
|
+
## Troubleshooting
|
|
281
|
+
|
|
282
|
+
| Symptom | Fastest check |
|
|
283
|
+
|---|---|
|
|
284
|
+
| No viewer update | Confirm source and viewer use the same room with opposite roles. |
|
|
285
|
+
| WebSocket connects but no snapshot | Confirm capture called `start()` or the adapter installed before navigation. |
|
|
286
|
+
| Remote control does nothing | Confirm the Playwright/CDP `authorizeControl` hook approves the action. |
|
|
287
|
+
| Styles drift after class changes | Try `styleMode: 'cssom'` and inspect `styleStrategy.fallbacks`. |
|
|
288
|
+
| Bookmarklet fails silently | Listen for `phantomstream:bookmarklet-error` and check page CSP. |
|
|
289
|
+
| Private text appears in the mirror | Add `blockSelector`, `maskTextSelector`, or `maskInputs`; masking must happen capture-side. |
|
package/docs/RELEASE.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# PhantomStream Release Gates
|
|
2
|
+
|
|
3
|
+
This document records the release checks for the 0.x npm package. It is a
|
|
4
|
+
pre-publish checklist, not permission to publish.
|
|
5
|
+
|
|
6
|
+
## Local Preflight
|
|
7
|
+
|
|
8
|
+
Run these from a clean checkout before cutting a release:
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm ci
|
|
12
|
+
npm run package:check
|
|
13
|
+
npm publish --dry-run --access public
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
`package:check` runs the full `npm test` suite, declaration generation,
|
|
17
|
+
publint, ATTW in ESM-only mode, dry-run pack, and a tarball install smoke. The
|
|
18
|
+
smoke installs the packed `.tgz` into a fresh temp project, imports every
|
|
19
|
+
public subpath, and runs `phantom-stream --help`.
|
|
20
|
+
|
|
21
|
+
## Trusted Publisher Setup
|
|
22
|
+
|
|
23
|
+
Preferred publishing uses npm trusted publishing through GitHub Actions OIDC.
|
|
24
|
+
Configure the npm package trusted publisher with these fields:
|
|
25
|
+
|
|
26
|
+
| Field | Value |
|
|
27
|
+
|---|---|
|
|
28
|
+
| Package | `@full-self-browsing/phantom-stream` |
|
|
29
|
+
| Owner | `fullselfbrowsing` |
|
|
30
|
+
| Repository | `PhantomStream` |
|
|
31
|
+
| Workflow filename | `publish.yml` |
|
|
32
|
+
| Workflow path | `.github/workflows/publish.yml` |
|
|
33
|
+
| Environment | `npm-publish` |
|
|
34
|
+
|
|
35
|
+
The workflow uses GitHub-hosted `ubuntu-latest`, grants `contents: read` and
|
|
36
|
+
`id-token: write`, configures the npm registry URL, runs
|
|
37
|
+
`npm run package:check`, and then runs `npm publish --access public`.
|
|
38
|
+
|
|
39
|
+
No `NPM_TOKEN` secret is required for the default trusted-publishing path.
|
|
40
|
+
|
|
41
|
+
## Publish Boundary
|
|
42
|
+
|
|
43
|
+
Real publishing is a human/authentication gate. Do not run
|
|
44
|
+
`npm publish --access public` unless the package owner has confirmed npm write
|
|
45
|
+
permission or trusted publishing is configured, account 2FA/trust requirements
|
|
46
|
+
are satisfied, and the user has explicitly approved the publish action for
|
|
47
|
+
this workspace.
|
|
48
|
+
|
|
49
|
+
## Staged Release Option
|
|
50
|
+
|
|
51
|
+
For review before public release:
|
|
52
|
+
|
|
53
|
+
1. Run local preflight and commit the resulting package files.
|
|
54
|
+
2. Open a draft GitHub release for the tag.
|
|
55
|
+
3. Protect the `npm-publish` environment with required reviewers.
|
|
56
|
+
4. Publish the GitHub release only after review; the workflow still runs
|
|
57
|
+
`npm run package:check` before the final `npm publish --access public`.
|
|
58
|
+
|
|
59
|
+
If trusted publishing is not configured yet, stop after dry-run and configure
|
|
60
|
+
the npm trusted publisher before attempting the release workflow.
|
package/docs/SECURITY.md
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# PhantomStream Security
|
|
2
|
+
|
|
3
|
+
This document is the embed security contract for PhantomStream's capture -> wire -> render
|
|
4
|
+
pipeline. It describes the always-on protections implemented in `src/capture/index.js`,
|
|
5
|
+
`src/renderer/sanitize.js`, `src/renderer/diff.js`, `src/renderer/snapshot.js`, and
|
|
6
|
+
`src/renderer/index.js`, plus the responsibilities a host must preserve when embedding the
|
|
7
|
+
viewer.
|
|
8
|
+
|
|
9
|
+
## 1. Threat Model
|
|
10
|
+
|
|
11
|
+
The page being mirrored is attacker-influenced input. Its DOM, attributes, CSS, text, links,
|
|
12
|
+
forms, dialogs, and overlays can all reach the capture side. PhantomStream's job is to preserve
|
|
13
|
+
benign visual fidelity while making mirrored content safe to render in an embedded viewer and
|
|
14
|
+
while ensuring configured private content never leaves the captured page.
|
|
15
|
+
|
|
16
|
+
| Pattern | Primary risk | Mitigation layers |
|
|
17
|
+
|---|---|---|
|
|
18
|
+
| Inline event handlers (`onclick`, `onload`, namespaced handler attrs) | Script execution in the mirror | Capture `sanitizeForWire`, render `sanitizeFragment` / `sanitizeAttrValue`, no `allow-scripts` sandbox |
|
|
19
|
+
| `javascript:`, `vbscript:`, `data:text/html` URLs | Script or HTML navigation | Capture and render URL scheme blocklist; CSP `default-src 'none'` |
|
|
20
|
+
| Nested `srcdoc` attacker iframes | Reintroduced document execution surface | `srcdoc` attributes dropped at both chokepoints |
|
|
21
|
+
| `<object>` / `<embed>` plugin shells | Plugin or nested resource execution | Dropped entirely at both chokepoints |
|
|
22
|
+
| Namespace-confusion mXSS (`svg`, `math`, `xlink:href`, style breakouts) | Parser mutation turns inert-looking markup active | DOM-fragment render sanitization, namespace-aware attr scrubs, CSS breakout scrub |
|
|
23
|
+
| CSS vectors (`expression()`, `-moz-binding`, `url(javascript:)`, hostile `@import`) | Legacy script or unwanted fetch path | Targeted CSS value scrub at capture and render |
|
|
24
|
+
| CSSOM `styleSources[]` and `DIFF_OP.STYLE_SOURCE` ops | Stylesheet text becomes a new insertion surface | Capture-side CSS scrub, render-side `scrubCssText`, CSP, and no `allow-scripts` sandbox |
|
|
25
|
+
| Password and PII leakage | Private text leaves the page | Capture-side masking before transport; password masking is non-configurable |
|
|
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
|
+
| Cross-origin iframe content | Browser-origin data leakage | Capture never reads cross-origin iframe content; renderer shows content-free placeholders only |
|
|
28
|
+
| Live value diffs | Typed values bypass snapshot masking | `DIFF_OP.VALUE` payloads route through capture-side value masking before transport |
|
|
29
|
+
| Future serialization path bypass | A new writer skips sanitization or masking | Static scan in `tests/security-chokepoint-purity.test.js` |
|
|
30
|
+
| New renderer `innerHTML` sink or sandbox weakening | Render-side defense bypass | InnerHTML allowlist and `allow-scripts` forbidden scan |
|
|
31
|
+
| Security contract rot | Docs stop matching shipped controls | `docs/SECURITY.md` marker guard in the purity test |
|
|
32
|
+
|
|
33
|
+
## 2. Defense-In-Depth Pipeline
|
|
34
|
+
|
|
35
|
+
PhantomStream uses five layers in order. No layer is optional, and there is no opt-out config
|
|
36
|
+
on either the capture or renderer side.
|
|
37
|
+
|
|
38
|
+
1. **Capture chokepoint: `sanitizeForWire` (`src/capture/index.js`)** - every snapshot,
|
|
39
|
+
add-op subtree, shadow root sidecar, same-origin frame payload, subtree response,
|
|
40
|
+
attr op, text op, value diff, head inline style value, CSSOM `styleSources[]` entry,
|
|
41
|
+
and `DIFF_OP.STYLE_SOURCE` op routes through this named function before
|
|
42
|
+
`transport.send`. It strips, neutralizes, masks, or drops content only on detached
|
|
43
|
+
clones and wire values; the live page is not mutated.
|
|
44
|
+
2. **Wire** - protocol messages carry already-sanitized and already-masked values. The D7
|
|
45
|
+
differential ledger entry documents the intentional divergence from the raw reference stream.
|
|
46
|
+
3. **Render chokepoints: `sanitizeFragment` and `sanitizeAttrValue`
|
|
47
|
+
(`src/renderer/sanitize.js`)** - add-op HTML is parsed in a `<template>`, scrubbed as a
|
|
48
|
+
DOM fragment, and then imported. Shadow root replacements, same-origin frame srcdoc
|
|
49
|
+
payloads, and `STREAM.SUBTREE_RESPONSE` installs follow the same parse-then-sanitize
|
|
50
|
+
rule before becoming addressable. Attr ops are scrubbed before `setAttribute`, and
|
|
51
|
+
CSSOM `styleSources[]` / `DIFF_OP.STYLE_SOURCE` text routes through `scrubCssText`
|
|
52
|
+
before a mirror `<style>` node is written. The viewer also runs a post-parse
|
|
53
|
+
`sanitizeFragment` scrub on the mirror document after srcdoc loads.
|
|
54
|
+
4. **Srcdoc CSP meta** - every snapshot srcdoc includes this adopted policy:
|
|
55
|
+
|
|
56
|
+
```text
|
|
57
|
+
default-src 'none'; img-src http: https: data:; style-src http: https: 'unsafe-inline'; font-src http: https: data:
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
The `style-src http: https: 'unsafe-inline'` adjustment is intentional. The original baseline
|
|
61
|
+
allowed inline styles only, but capture deliberately emits external stylesheet links via
|
|
62
|
+
`stylesheets[]` in `src/capture/index.js`; blocking those links would break ordinary mirror
|
|
63
|
+
fidelity. Script blocking remains unchanged because `default-src 'none'` is still present and
|
|
64
|
+
no `script-src` is introduced.
|
|
65
|
+
5. **Iframe Sandbox token contract** - the viewer iframe's sandbox attribute is exactly
|
|
66
|
+
`allow-same-origin`. It is never `allow-scripts`, and no other token is added. `createViewer`
|
|
67
|
+
writes the attribute, reads it back, and throws `viewer-sandbox-invalid` if the token list is
|
|
68
|
+
not exactly one token. `allow-same-origin` keeps the mirror document parent-accessible for diff
|
|
69
|
+
applies; omitting `allow-scripts` is what makes mirrored script inert.
|
|
70
|
+
|
|
71
|
+
Nested same-origin frame mirrors are also inert `srcdoc` documents and must not
|
|
72
|
+
gain `allow-scripts`. Cross-origin iframe content is never captured; placeholder
|
|
73
|
+
metadata must not imply remote document access.
|
|
74
|
+
|
|
75
|
+
The CSP is delivered by meta because the mirror is `srcdoc`, not a fetched URL. Meta delivery
|
|
76
|
+
does not enforce `frame-ancestors`, `sandbox`, or `report-uri`; adding those directives to the
|
|
77
|
+
meta policy would be a silent no-op. The iframe-level sandbox attribute is the sandbox control,
|
|
78
|
+
and host embedding constraints belong to the host application.
|
|
79
|
+
|
|
80
|
+
## 3. Sanitization Policy
|
|
81
|
+
|
|
82
|
+
The policy is blocklist-based and fidelity-first. An allowlist was rejected because PhantomStream
|
|
83
|
+
must mirror arbitrary real pages without breaking benign markup.
|
|
84
|
+
|
|
85
|
+
- Event-handler attributes (`on*`) are removed in capture and render paths.
|
|
86
|
+
- Dangerous URL schemes are removed for URL-bearing attrs, including `href`, `src`, `action`,
|
|
87
|
+
`poster`, `data`, `formaction`, `xlink:href`, and `srcset` candidates.
|
|
88
|
+
- `srcdoc` attributes are dropped.
|
|
89
|
+
- `script`, `noscript`, `object`, and `embed` subtrees are dropped. `object` / `embed` are
|
|
90
|
+
removed rather than replaced because they are plugin or nested-resource shells and do not carry
|
|
91
|
+
useful mirror fidelity under the sandbox.
|
|
92
|
+
- CSS is value-scrubbed for unsafe `url()`, `expression()`, `-moz-binding`, hostile `@import`,
|
|
93
|
+
and `</style>` breakout shapes. Relative URLs remain allowed so captured same-page assets and
|
|
94
|
+
ordinary author CSS keep rendering.
|
|
95
|
+
- CSSOM mode (`styleMode: 'cssom'`) uses the same CSS scrub for snapshot `styleSources[]`
|
|
96
|
+
and live `DIFF_OP.STYLE_SOURCE` ops. The optional
|
|
97
|
+
`fetchStylesheet({ href, scope, ownerKind })` hook is host code, is never invoked by
|
|
98
|
+
default, and must return CSS text for PhantomStream to sanitize before transport.
|
|
99
|
+
- Render-side sanitization operates on parsed DOM fragments, never on a sanitized string that is
|
|
100
|
+
serialized and reparsed. String scrub/reparse is the mXSS anti-pattern this pipeline avoids.
|
|
101
|
+
- Strips and scrubs are counted and logged. They are never silent health events.
|
|
102
|
+
|
|
103
|
+
## 4. Masking Guarantees
|
|
104
|
+
|
|
105
|
+
Masking is capture-side only. Masked content is transformed before transport and never appears
|
|
106
|
+
on the wire in raw form.
|
|
107
|
+
|
|
108
|
+
- Password input values are always masked, independent of `maskInputs`.
|
|
109
|
+
- `maskInputs: true` masks input, textarea, and related form value surfaces.
|
|
110
|
+
- `maskTextSelector` masks text owned by matching elements and descendants. The default transform
|
|
111
|
+
replaces each non-whitespace character with `*`, preserving whitespace and length.
|
|
112
|
+
- `blockSelector` emits a placeholder box with only `data-fsb-nid`, `rr_width`, and `rr_height`.
|
|
113
|
+
Attributes, children, and text from the blocked subtree are not serialized.
|
|
114
|
+
- Invalid selectors fail at factory time with `invalid-mask-selector` instead of silently falling
|
|
115
|
+
back to an unsafe state.
|
|
116
|
+
- Custom mask functions are fail-closed: thrown errors are logged and the default asterisk mask is
|
|
117
|
+
used so raw values do not leak.
|
|
118
|
+
- Event-driven `DIFF_OP.VALUE` payloads use the same masking policy as snapshots and attrs.
|
|
119
|
+
Password, `maskInputs`, and `maskInputFn` behavior is enforced before the value diff leaves
|
|
120
|
+
the page. Health and diagnostics stay content-free and do not include typed values.
|
|
121
|
+
- `select` / `option` display text remains a known privacy boundary: value masking does not make
|
|
122
|
+
option labels private unless they are also covered by `maskTextSelector` or `blockSelector`.
|
|
123
|
+
|
|
124
|
+
## 5. Host must-nevers
|
|
125
|
+
|
|
126
|
+
Hosts embedding PhantomStream must preserve these rules:
|
|
127
|
+
|
|
128
|
+
- Never add iframe sandbox tokens, especially `allow-scripts`.
|
|
129
|
+
- Never render wire payloads outside `createViewer`.
|
|
130
|
+
- Never re-serialize the mirror document into another `innerHTML` sink.
|
|
131
|
+
- Never treat dialog, prompt, overlay, or custom overlay text as HTML. Built-in overlays use
|
|
132
|
+
`textContent`; custom renderers should do the same.
|
|
133
|
+
- Never add an opt-out switch for the capture or render sanitizers.
|
|
134
|
+
- Never weaken the adopted CSP policy below script-blocking.
|
|
135
|
+
|
|
136
|
+
## 6. Residual Risks
|
|
137
|
+
|
|
138
|
+
Snapshot `payload.html` remains string-raw at the srcdoc assembly layer by design. Scrubbing an
|
|
139
|
+
HTML string and then asking the browser to parse it again is the mutation-XSS failure mode. The
|
|
140
|
+
protection chain is instead capture `sanitizeForWire`, render post-parse `sanitizeFragment`, the
|
|
141
|
+
CSP meta, and the no-`allow-scripts` sandbox.
|
|
142
|
+
|
|
143
|
+
Novel CSS or markup parser vectors can still appear after this release. They are backstopped by
|
|
144
|
+
the CSP and sandbox, and strip counters/logs are the observability signal for sanitizer activity.
|
|
145
|
+
|
|
146
|
+
The dialog/overlay side-channel boundary is privacy-scoped. Dialog `detail.message`, prompt
|
|
147
|
+
`defaultValue`, overlay labels, and custom overlay payload text do not have a stable owner element
|
|
148
|
+
for selector-based masking. If page script copies sensitive content into a dialog or overlay string,
|
|
149
|
+
selector-based capture masking cannot identify it as belonging to a masked element. The viewer
|
|
150
|
+
renders these strings through `textContent`, so this residual is not markup injection; it is the
|
|
151
|
+
rrweb-parity privacy boundary tracked as T-03-26.
|
|
152
|
+
|
|
153
|
+
Closed shadow roots, cross-origin iframe content, and media stream pixels remain
|
|
154
|
+
non-captured content. PhantomStream does not bypass those browser boundaries.
|
|
155
|
+
CSSOM mode is stylesheet capture only; it does not capture protected browser
|
|
156
|
+
content or weaken the sanitizer, CSP, or sandbox constraints.
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# Paper Outline — PhantomStream: DOM-Native Live Mirroring for Agentic Browsing
|
|
2
|
+
|
|
3
|
+
> Working title. Status: outline. Venue candidates: WWW / UIST / CHI (system track),
|
|
4
|
+
> or an agents/HCI workshop for an early version.
|
|
5
|
+
|
|
6
|
+
## Abstract (draft sketch)
|
|
7
|
+
|
|
8
|
+
AI agents increasingly operate real browsers on a user's behalf. Supervising such an agent
|
|
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.
|
|
21
|
+
|
|
22
|
+
## 1. Introduction
|
|
23
|
+
|
|
24
|
+
- The agentic-browsing supervision problem: trust, observability, intervention.
|
|
25
|
+
- Why pixels are the wrong abstraction for watching an agent: no element identity, no
|
|
26
|
+
cheap idle state, no semantic overlay channel.
|
|
27
|
+
- Contributions:
|
|
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.
|
|
35
|
+
|
|
36
|
+
## 2. Related work
|
|
37
|
+
|
|
38
|
+
- **Session replay:** rrweb, SessionStack, LogRocket — record/replay vs. live mirroring;
|
|
39
|
+
rrweb's stylesheet capture vs. our computed-style inlining (discuss trade-off honestly).
|
|
40
|
+
- **Remote display:** VNC/RDP, WebRTC screen capture, Chrome DevTools Protocol screencast.
|
|
41
|
+
- **Co-browsing:** Surfly, Upscope — commercial DOM co-browsing, little published detail.
|
|
42
|
+
- **DOM diffing/virtual DOM literature**; CRDTs for DOM (peritext-adjacent) — why a
|
|
43
|
+
single-writer mirror needs none of that.
|
|
44
|
+
- **Agent observability:** browser-use/agent frameworks' screenshot streams; computer-use
|
|
45
|
+
model viewers.
|
|
46
|
+
|
|
47
|
+
## 3. System design
|
|
48
|
+
|
|
49
|
+
Map of docs/ARCHITECTURE.md §§2–4, reframed as design decisions with rationale:
|
|
50
|
+
|
|
51
|
+
- 3.1 Node identity (nid stamping; observability trade-off; WeakMap alternative)
|
|
52
|
+
- 3.2 Snapshot serialization (parallel TreeWalker, URL absolutification, canvas, iframes)
|
|
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)
|