@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Lakshman Turlapati
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# PhantomStream
|
|
4
|
+
|
|
5
|
+
*DOM-native live browser mirroring. A real tab streamed as structured DOM instead of pixels.*
|
|
6
|
+
|
|
7
|
+
PhantomStream mirrors a live browser tab to a remote viewer as structured DOM data, not video. It sends one style-inlined snapshot and then tiny MutationObserver diffs addressed by stable node IDs, so the viewer gets a live, semantically addressable, remotely controllable copy of the page at a fraction of the bandwidth of screen streaming.
|
|
8
|
+
|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
12
|
+

|
|
13
|
+

|
|
14
|
+

|
|
15
|
+
|
|
16
|
+
[](https://github.com/fullselfbrowsing/PhantomStream/stargazers)
|
|
17
|
+
[](https://github.com/fullselfbrowsing/PhantomStream/issues)
|
|
18
|
+
[](https://github.com/fullselfbrowsing/PhantomStream/commits/main)
|
|
19
|
+
|
|
20
|
+
[The Problem](#the-problem) · [The Solution](#the-solution) · [Why DOM Streaming](#why-dom-streaming-instead-of-video) · [Architecture](#architecture) · [Features](#features) · [Tech Stack](#tech-stack) · [Getting Started](#getting-started) · [Quickstarts](docs/QUICKSTARTS.md) · [Documentation](#documentation) · [Roadmap](#roadmap)
|
|
21
|
+
|
|
22
|
+
</div>
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## The Problem
|
|
27
|
+
|
|
28
|
+
When an AI agent drives a browser, the human supervising it needs a live view of what the agent is doing. The obvious tools are video. WebRTC, a CDP screencast, or a sequence of screenshots all send pixels. Pixels are heavy. Every frame costs bandwidth whether the page changed or not, encoding and decoding add latency, and the result is lossy and resolution bound.
|
|
29
|
+
|
|
30
|
+
Worse, pixels are opaque. The watcher cannot ask which element the agent is touching, cannot highlight a node, cannot annotate the view, and cannot reliably drive the page back. Remote control over a video stream means clicking pixel coordinates against a frame that may already be stale, so a misaligned click lands on the wrong thing.
|
|
31
|
+
|
|
32
|
+
## The Solution
|
|
33
|
+
|
|
34
|
+
PhantomStream streams the DOM itself. It captures the page once as a style-inlined snapshot, assigns stable identifiers in a WeakMap, and then watches the page with a MutationObserver. From that point on it sends only small diffs (`add`, `rm`, `attr`, `text`) keyed by node ID, batched to the page's own paint cadence. Snapshot and add-op identity travels in `nodeIds` sidecars, so the live page is not mutated with framework attributes. The viewer rebuilds the document inside a sandboxed iframe and applies each diff by ID.
|
|
35
|
+
|
|
36
|
+
The payoff is a mirror that is cheap, exact, and addressable. Bandwidth tracks how much the page actually changes rather than the frame rate. Text renders natively at any resolution. Remote control targets real elements by their stable IDs instead of guessing at coordinates, so a click on the viewer maps back to the exact node on the source.
|
|
37
|
+
|
|
38
|
+
PhantomStream began as milestone **v0.9.9.1 "Phantom Stream"** inside [FSB (Full Self-Browsing)](https://github.com/fullselfbrowsing/FSB), where it powers the dashboard's live preview of automated browsing sessions. This repository turns it into three things at once: a standalone plug-and-play framework for anything that needs a live view into a browser it controls, an SDK that FSB can plug back in, and the working repository for an accompanying research paper.
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Why DOM Streaming Instead of Video
|
|
43
|
+
|
|
44
|
+
| | Video / screenshot streaming | PhantomStream (DOM streaming) |
|
|
45
|
+
|---|---|---|
|
|
46
|
+
| **Bandwidth** | Continuous frames, independent of page content | One snapshot, then tiny diffs only when the page changes |
|
|
47
|
+
| **Latency** | Encode, transmit, then decode per frame | A text mutation is one small JSON op |
|
|
48
|
+
| **Fidelity** | Lossy and resolution bound | Exact DOM, native text rendering, resolution independent |
|
|
49
|
+
| **Remote control** | Pixel coordinates against a possibly stale frame | Real elements addressed by stable node IDs |
|
|
50
|
+
| **Inspectability** | Opaque pixels | The mirror *is* a DOM, so it is queryable, highlightable, annotatable |
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## Architecture
|
|
55
|
+
|
|
56
|
+
PhantomStream is a four-stage pipeline. The page is captured, the host wraps each message for transport, a relay fans messages out to viewers, and the viewer rebuilds and applies them. Remote control runs the same path in reverse.
|
|
57
|
+
|
|
58
|
+
```mermaid
|
|
59
|
+
graph LR
|
|
60
|
+
subgraph Page["Page (capture)"]
|
|
61
|
+
SNAP["Snapshot: clone + inline styles + nid stamp"]
|
|
62
|
+
DIFF["Diffs: rAF-batched MutationObserver"]
|
|
63
|
+
end
|
|
64
|
+
subgraph Host["Host (transport)"]
|
|
65
|
+
ENV["LZ-string envelope, session stamping, watchdog"]
|
|
66
|
+
end
|
|
67
|
+
subgraph Server["Relay (server)"]
|
|
68
|
+
FAN["WebSocket fan-out, 1 MiB cap, backpressure drop"]
|
|
69
|
+
end
|
|
70
|
+
subgraph View["Viewer (render)"]
|
|
71
|
+
REBUILD["Sandboxed iframe, diff apply by nid, overlays, scale-to-fit"]
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
SNAP --> ENV
|
|
75
|
+
DIFF --> ENV
|
|
76
|
+
ENV --> FAN
|
|
77
|
+
FAN --> REBUILD
|
|
78
|
+
REBUILD -. remote control .-> FAN
|
|
79
|
+
FAN -. remote control .-> ENV
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Core mechanisms (see [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) for the full treatment and [docs/SECURITY.md](docs/SECURITY.md) for the embed security contract):
|
|
83
|
+
|
|
84
|
+
- **Stable node identity.** Capture owns identity in a `WeakMap<Element, string>` and emits `nodeIds` sidecars with snapshots and add ops. All diff ops and remote-control actions address nodes by this key, so a late diff always lands on the right mirror element without mutating the live page.
|
|
85
|
+
- **Curated computed-style capture.** Roughly 85 visual-fidelity CSS properties are inlined per element rather than all 300 plus, with default-value elision. This is the fix that took a YouTube serialize from 45 seconds down to interactive.
|
|
86
|
+
- **Display-matched diffing.** Mutations batch and flush on `requestAnimationFrame`, so the mirror updates at the same cadence the page paints.
|
|
87
|
+
- **Budgeted snapshots.** Snapshots truncate to a relay-safe size by dropping whole subtrees below 3x the viewport, never mid-element, after a single batched layout read.
|
|
88
|
+
- **Dual watchdogs.** A capture-side self-watchdog rescues a stuck mutation queue. A second host-side alarm survives service-worker eviction and requests a fresh snapshot if the stream strands silently.
|
|
89
|
+
- **Session identity.** Every message carries a `streamSessionId` plus a `snapshotId`. The viewer rejects stale messages, so late diffs from a previous page can never corrupt the mirror.
|
|
90
|
+
- **Side channels.** Scroll position, automation overlays (action glow, progress card), and native `alert` / `confirm` / `prompt` dialogs mirror alongside the DOM.
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## Features
|
|
95
|
+
|
|
96
|
+
| Feature | Description |
|
|
97
|
+
|---|---|
|
|
98
|
+
| **Stable node IDs** | Capture uses WeakMap identity and `nodeIds` sidecars. Diffs and remote-control actions address nodes by ID, never by coordinate or fragile selector. |
|
|
99
|
+
| **Curated style inlining** | About 85 fidelity-critical CSS properties are inlined per element with default elision, keeping heavy pages interactive instead of stalling on full style enumeration. |
|
|
100
|
+
| **CSSOM capture mode** | Opt-in `styleMode: 'cssom'` transports scoped stylesheet sources and live `style-source` ops for document, open shadow root, and same-origin frame scopes. |
|
|
101
|
+
| **Paint-cadence diffs** | A MutationObserver batches changes and flushes on `requestAnimationFrame`, so the wire carries one compact op per real change at the page's own update rate. |
|
|
102
|
+
| **Budgeted snapshots** | Snapshots stay under the relay's per-message cap by dropping offscreen subtrees on whole-element boundaries after a single layout read. |
|
|
103
|
+
| **Session stamping** | A per-session `streamSessionId` and per-snapshot `snapshotId` ride every message, so the viewer can reject anything from a stale page. |
|
|
104
|
+
| **Dual watchdogs** | A capture-side timer and a host-side alarm independently recover a wedged stream by forcing a flush or a fresh snapshot. |
|
|
105
|
+
| **Compressed envelope** | Payloads above 1 KB are LZ-string compressed when smaller, carried as a self-identifying `{ _lz: true, d }` envelope that is stateless per frame. |
|
|
106
|
+
| **Sandboxed rendering** | The viewer rebuilds the page inside an iframe sandboxed to exactly `allow-same-origin`, never `allow-scripts`, with a CSP meta tag and a post-parse scrub. |
|
|
107
|
+
| **Capture-side sanitization** | Serialization strips `on*` handlers, dangerous URL schemes, `srcdoc`, and `object` / `embed` subtrees on the wire clone only. The live page is never touched. |
|
|
108
|
+
| **Privacy masking** | `blockSelector`, `maskTextSelector`, `maskInputs`, and custom mask functions redact sensitive content before it leaves the page, with passwords always masked. |
|
|
109
|
+
| **Side-channel mirroring** | Scroll, automation overlays, and native dialogs stream alongside the DOM and render as host-document overlays above the mirror. |
|
|
110
|
+
| **Playwright adapter** | Drop the capture core into a Playwright or CDP page through a ready-made adapter, including authorized reverse remote control. |
|
|
111
|
+
| **Pluggable transport** | Capture, viewer, and relay all talk through a small transport seam, so the same core runs over WebSocket, an in-page loopback channel, or any channel you supply. |
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## Tech Stack
|
|
116
|
+
|
|
117
|
+
| Layer | Technology | Why |
|
|
118
|
+
|---|---|---|
|
|
119
|
+
| **Language** | Plain JavaScript (ES2020+), ES modules, JSDoc types | The capture core injects as a plain script into a content script, `addInitScript`, or a bookmarklet, with no runtime build step |
|
|
120
|
+
| **Runtime** | Node.js 18+ (tested on v24) | Native `node:test` runner and the relay server both run on the standard runtime |
|
|
121
|
+
| **Transport** | WebSocket (`ws`) plus a self-identifying LZ-string envelope | Backward-compatible with FSB's shipped `{ _lz, d }` wire format, stateless per frame |
|
|
122
|
+
| **Rendering** | Sandboxed iframe, host-document overlay layer | Renders attacker-influenced HTML with script execution disabled by construction |
|
|
123
|
+
| **Adapters** | Playwright / CDP injection adapter | Mirrors and remotely controls a Playwright-driven page out of the box |
|
|
124
|
+
| **Tests** | `node:test`, `jsdom`, a differential oracle against the FSB reference | Verifies behavioral parity with the shipped implementation, not just unit correctness |
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## Getting Started
|
|
129
|
+
|
|
130
|
+
PhantomStream is published as `@full-self-browsing/phantom-stream` and exposes one subpath per stage. For adapter-specific setup paths, see [docs/QUICKSTARTS.md](docs/QUICKSTARTS.md).
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
npm install @full-self-browsing/phantom-stream
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
**Capture a page** (runs in the page context):
|
|
137
|
+
|
|
138
|
+
```js
|
|
139
|
+
import { createCapture } from '@full-self-browsing/phantom-stream/capture';
|
|
140
|
+
import { createWebSocketTransport } from '@full-self-browsing/phantom-stream/transport/websocket';
|
|
141
|
+
|
|
142
|
+
const transport = createWebSocketTransport({
|
|
143
|
+
url: 'wss://relay.example.com/ws?room=ROOM_KEY&role=source',
|
|
144
|
+
role: 'source'
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
const capture = createCapture({
|
|
148
|
+
transport,
|
|
149
|
+
skipElement: (el) => el.id === 'my-own-overlay' // exclude your own UI
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
capture.start(); // snapshot once, then stream diffs
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Use `styleMode: 'cssom'` when you want stylesheet-centric capture instead of
|
|
156
|
+
generated computed inline styles.
|
|
157
|
+
|
|
158
|
+
**Mirror it in a viewer** (runs in the remote context):
|
|
159
|
+
|
|
160
|
+
```js
|
|
161
|
+
import { createViewer } from '@full-self-browsing/phantom-stream/renderer';
|
|
162
|
+
import { createWebSocketTransport } from '@full-self-browsing/phantom-stream/transport/websocket';
|
|
163
|
+
|
|
164
|
+
const transport = createWebSocketTransport({
|
|
165
|
+
url: 'wss://relay.example.com/ws?room=ROOM_KEY&role=viewer',
|
|
166
|
+
role: 'viewer'
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
const viewer = createViewer({
|
|
170
|
+
container: document.getElementById('mirror'),
|
|
171
|
+
transport
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
viewer.on('state', (e) => console.log('viewer is', e.state)); // connecting | live | stale | disconnected
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
**Run a relay** (Node server that fans messages between source and viewers):
|
|
178
|
+
|
|
179
|
+
```js
|
|
180
|
+
import http from 'node:http';
|
|
181
|
+
import { createRelay, createWebSocketRelayBackend } from '@full-self-browsing/phantom-stream/relay';
|
|
182
|
+
|
|
183
|
+
const relay = createRelay(); // routing core: 1 MiB per-message cap, backpressure drop
|
|
184
|
+
const server = http.createServer();
|
|
185
|
+
createWebSocketRelayBackend({ server, relay, path: '/ws' });
|
|
186
|
+
server.listen(8787);
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Clients join a room by passing `?room=<id>&role=source|viewer` on the connection URL. See `examples/two-tab-demo/server.js` for the full room and role wiring.
|
|
190
|
+
|
|
191
|
+
**Run the tests and demos** straight from the repository:
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
npm test # node:test suite plus the differential oracle
|
|
195
|
+
npm run demo # two-tab demo: a source tab mirrored in a viewer tab
|
|
196
|
+
npm run demo:playwright # Playwright drives a page while a viewer mirrors it
|
|
197
|
+
npm run example:loopback # embedded SDK demo: one page mirrors itself in place
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## Project Structure
|
|
203
|
+
|
|
204
|
+
```text
|
|
205
|
+
src/ The framework
|
|
206
|
+
protocol/ Wire types, LZ envelope, shared constants, session identity
|
|
207
|
+
capture/ Page-side snapshot + MutationObserver diff streaming
|
|
208
|
+
renderer/ Viewer reconstruction: snapshot, diff apply, overlays
|
|
209
|
+
relay/ Transport-agnostic routing core + WebSocket backend
|
|
210
|
+
transport/websocket.js Browser-compatible WebSocket transport for both ends
|
|
211
|
+
adapters/ Playwright / CDP injection adapter
|
|
212
|
+
reference/ Verbatim FSB source, pinned to the shipped commit
|
|
213
|
+
extension/ Capture content script, ws client, background excerpts
|
|
214
|
+
dashboard/ FSB viewer implementation
|
|
215
|
+
server/ FSB relay server
|
|
216
|
+
tests/ Framework tests
|
|
217
|
+
differential/ Oracle-based parity checks against the reference
|
|
218
|
+
docs/ Architecture, security, design history, paper outline
|
|
219
|
+
examples/ Two-tab, Playwright, and loopback demos
|
|
220
|
+
bin/phantom-stream.js CLI entry point for the demos
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
## Documentation
|
|
226
|
+
|
|
227
|
+
| Document | What it covers |
|
|
228
|
+
|---|---|
|
|
229
|
+
| [docs/QUICKSTARTS.md](docs/QUICKSTARTS.md) | Installable package paths for embedded loopback, WebSocket demo, Playwright/CDP, extension MV3, bookmarklet, and CSSOM mode |
|
|
230
|
+
| [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) | End-to-end technical description of the capture, transport, relay, and renderer pipeline, plus known limitations |
|
|
231
|
+
| [docs/SECURITY.md](docs/SECURITY.md) | The embed security contract: threat model, sanitization, masking, CSP, and sandbox guarantees |
|
|
232
|
+
| [docs/DESIGN-HISTORY.md](docs/DESIGN-HISTORY.md) | How the system evolved, what failed along the way, and why the current shape won |
|
|
233
|
+
| [docs/RELEASE.md](docs/RELEASE.md) | Package validation and publish-gate checklist |
|
|
234
|
+
| [docs/paper/OUTLINE.md](docs/paper/OUTLINE.md) | Research paper structure and the evaluation plan against video and rrweb baselines |
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
## Roadmap
|
|
239
|
+
|
|
240
|
+
| Stage | Status |
|
|
241
|
+
|---|---|
|
|
242
|
+
| Protocol module: wire types, envelope, constants, session identity | Shipped |
|
|
243
|
+
| Capture core decoupled from `chrome.runtime` and the FSB namespace | Shipped |
|
|
244
|
+
| Renderer decoupled from the FSB dashboard | Shipped |
|
|
245
|
+
| Transport-agnostic relay with a pluggable WebSocket backend | Shipped |
|
|
246
|
+
| WebSocket transport plus the Playwright / CDP adapter | Shipped |
|
|
247
|
+
| Security pipeline: sanitization, sandbox, privacy masking | Shipped |
|
|
248
|
+
| Reference demos: two-tab, Playwright, and embedded loopback | Shipped |
|
|
249
|
+
| Fidelity completion: WeakMap identity, nodeIds sidecars, shadow DOM, same-origin iframes, subtree recovery, and CSSOM mode | Shipped |
|
|
250
|
+
| Evaluation harness: bandwidth, latency, and fidelity against WebRTC, CDP screencast, and rrweb | Planned |
|
|
251
|
+
| Research paper draft | Planned |
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
## Research
|
|
256
|
+
|
|
257
|
+
PhantomStream is also a paper in progress on DOM-native browser mirroring for agentic browsing (see [docs/paper/OUTLINE.md](docs/paper/OUTLINE.md)). The short pitch: when an AI agent drives a browser, the human supervising it needs a live, trustworthy, low-latency view with semantic handles that answer which element the agent is touching, and pixel streaming gives none of that. The evaluation runs PhantomStream against WebRTC, CDP screencast, and rrweb baselines over a frozen site corpus under scripted activity levels.
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
## Provenance & License
|
|
262
|
+
|
|
263
|
+
Extracted from FSB at commit `867d6f0c` (2026-06-09), with the original milestone design history preserved under `reference/`. Released under the [MIT License](LICENSE), © 2026 Lakshman Turlapati.
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { startPlaywrightDemoServer } from '../examples/playwright-demo/server.js';
|
|
4
|
+
import { startBookmarkletDemoServer } from '../examples/bookmarklet-demo/server.js';
|
|
5
|
+
import { startExtensionDemoServer } from '../examples/extension-mv3/server.js';
|
|
6
|
+
import { startDemoServer } from '../examples/two-tab-demo/server.js';
|
|
7
|
+
|
|
8
|
+
const USAGE = [
|
|
9
|
+
'Usage: phantom-stream demo [--port <number>] [--no-open]',
|
|
10
|
+
' phantom-stream playwright-demo [--port <number>] [--drive] [--headed] [--no-open]',
|
|
11
|
+
' phantom-stream extension-demo [--port <number>] [--no-open]',
|
|
12
|
+
' phantom-stream bookmarklet-demo [--port <number>] [--no-open]',
|
|
13
|
+
].join('\n');
|
|
14
|
+
|
|
15
|
+
async function main(argv) {
|
|
16
|
+
var args = argv.slice();
|
|
17
|
+
var command = args.shift();
|
|
18
|
+
|
|
19
|
+
if (command === '--help' || command === '-h') {
|
|
20
|
+
printUsage();
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (command !== 'demo' && command !== 'playwright-demo' && command !== 'extension-demo'
|
|
25
|
+
&& command !== 'bookmarklet-demo') {
|
|
26
|
+
printUsage(command ? console.error : console.log);
|
|
27
|
+
return command ? 1 : 0;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
var parsed = command === 'playwright-demo'
|
|
31
|
+
? parsePlaywrightDemoArgs(args)
|
|
32
|
+
: parseDemoArgs(args);
|
|
33
|
+
if (parsed.help) {
|
|
34
|
+
printUsage();
|
|
35
|
+
return 0;
|
|
36
|
+
}
|
|
37
|
+
if (parsed.error) {
|
|
38
|
+
printUsage(console.error);
|
|
39
|
+
return 1;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
var demo = command === 'playwright-demo'
|
|
43
|
+
? await startPlaywrightDemoServer({
|
|
44
|
+
port: parsed.port,
|
|
45
|
+
launchDriver: parsed.drive && !parsed.noOpen,
|
|
46
|
+
headed: parsed.headed,
|
|
47
|
+
})
|
|
48
|
+
: command === 'extension-demo'
|
|
49
|
+
? await startExtensionDemoServer({ port: parsed.port })
|
|
50
|
+
: command === 'bookmarklet-demo'
|
|
51
|
+
? await startBookmarkletDemoServer({ port: parsed.port })
|
|
52
|
+
: await startDemoServer({ port: parsed.port });
|
|
53
|
+
if (command === 'playwright-demo') printPlaywrightDemoOutput(demo);
|
|
54
|
+
else if (command === 'extension-demo') printExtensionDemoOutput(demo);
|
|
55
|
+
else if (command === 'bookmarklet-demo') printBookmarkletDemoOutput(demo);
|
|
56
|
+
else printDemoOutput(demo);
|
|
57
|
+
|
|
58
|
+
var stopping = false;
|
|
59
|
+
async function stop() {
|
|
60
|
+
if (stopping) return;
|
|
61
|
+
stopping = true;
|
|
62
|
+
await demo.close();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
process.on('SIGINT', function () {
|
|
66
|
+
stop().catch(function (err) {
|
|
67
|
+
console.error(err && err.stack ? err.stack : err);
|
|
68
|
+
process.exitCode = 1;
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
process.on('SIGTERM', function () {
|
|
72
|
+
stop().catch(function (err) {
|
|
73
|
+
console.error(err && err.stack ? err.stack : err);
|
|
74
|
+
process.exitCode = 1;
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
return 0;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function parseDemoArgs(args) {
|
|
82
|
+
var out = { port: undefined, help: false, error: false, noOpen: false };
|
|
83
|
+
for (var i = 0; i < args.length; i++) {
|
|
84
|
+
var arg = args[i];
|
|
85
|
+
if (arg === '--help' || arg === '-h') {
|
|
86
|
+
out.help = true;
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
if (arg === '--no-open') {
|
|
90
|
+
out.noOpen = true;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (arg === '--port') {
|
|
94
|
+
var rawPort = args[++i];
|
|
95
|
+
var port = Number(rawPort);
|
|
96
|
+
if (!Number.isInteger(port) || port < 0 || port > 65535) {
|
|
97
|
+
out.error = true;
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
out.port = port;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
out.error = true;
|
|
104
|
+
return out;
|
|
105
|
+
}
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function parsePlaywrightDemoArgs(args) {
|
|
110
|
+
var out = {
|
|
111
|
+
port: undefined,
|
|
112
|
+
help: false,
|
|
113
|
+
error: false,
|
|
114
|
+
drive: false,
|
|
115
|
+
headed: false,
|
|
116
|
+
noOpen: false
|
|
117
|
+
};
|
|
118
|
+
for (var i = 0; i < args.length; i++) {
|
|
119
|
+
var arg = args[i];
|
|
120
|
+
if (arg === '--help' || arg === '-h') {
|
|
121
|
+
out.help = true;
|
|
122
|
+
return out;
|
|
123
|
+
}
|
|
124
|
+
if (arg === '--drive') {
|
|
125
|
+
out.drive = true;
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
if (arg === '--headed') {
|
|
129
|
+
out.headed = true;
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (arg === '--no-open') {
|
|
133
|
+
out.noOpen = true;
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (arg === '--port') {
|
|
137
|
+
var rawPort = args[++i];
|
|
138
|
+
var port = Number(rawPort);
|
|
139
|
+
if (!Number.isInteger(port) || port < 0 || port > 65535) {
|
|
140
|
+
out.error = true;
|
|
141
|
+
return out;
|
|
142
|
+
}
|
|
143
|
+
out.port = port;
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
out.error = true;
|
|
147
|
+
return out;
|
|
148
|
+
}
|
|
149
|
+
return out;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function printUsage(write) {
|
|
153
|
+
var output = typeof write === 'function' ? write : console.log;
|
|
154
|
+
output(USAGE);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function printDemoOutput(demo) {
|
|
158
|
+
console.log('PhantomStream demo running on 127.0.0.1');
|
|
159
|
+
console.log('Source tab: ' + demo.sourceUrl);
|
|
160
|
+
console.log('Viewer tab: ' + demo.viewerUrl);
|
|
161
|
+
console.log('Room: ' + demo.roomKeyPrefix + '...');
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function printPlaywrightDemoOutput(demo) {
|
|
165
|
+
console.log('PhantomStream Playwright demo running on 127.0.0.1');
|
|
166
|
+
console.log('Viewer: ' + demo.viewerUrl);
|
|
167
|
+
console.log('Driven page: ' + demo.drivenPageUrl);
|
|
168
|
+
console.log('Room: ' + demo.roomKeyPrefix + '...');
|
|
169
|
+
console.log('Control: default-deny');
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function printExtensionDemoOutput(demo) {
|
|
173
|
+
console.log('PhantomStream extension demo running on 127.0.0.1');
|
|
174
|
+
console.log('Extension directory: ' + demo.extensionDir);
|
|
175
|
+
console.log('Source page: ' + demo.sourceUrl);
|
|
176
|
+
console.log('Viewer: ' + demo.viewerUrl);
|
|
177
|
+
console.log('Room: ' + demo.roomKeyPrefix + '...');
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function printBookmarkletDemoOutput(demo) {
|
|
181
|
+
console.log('PhantomStream bookmarklet demo running on 127.0.0.1');
|
|
182
|
+
console.log('Source page: ' + demo.sourceUrl);
|
|
183
|
+
console.log('Viewer: ' + demo.viewerUrl);
|
|
184
|
+
console.log('Bookmarklet: ' + demo.bookmarklet);
|
|
185
|
+
console.log('Room: ' + demo.roomKeyPrefix + '...');
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
main(process.argv.slice(2)).then(function (code) {
|
|
189
|
+
if (typeof code === 'number') process.exitCode = code;
|
|
190
|
+
}).catch(function (err) {
|
|
191
|
+
console.error(err && err.stack ? err.stack : err);
|
|
192
|
+
process.exitCode = 1;
|
|
193
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create bookmarklet JavaScript source.
|
|
3
|
+
*
|
|
4
|
+
* @param {{scriptUrl: string, wsUrl: string, roomKey?: string}} options
|
|
5
|
+
* @returns {string}
|
|
6
|
+
*/
|
|
7
|
+
export function createBookmarkletSource(options: {
|
|
8
|
+
scriptUrl: string;
|
|
9
|
+
wsUrl: string;
|
|
10
|
+
roomKey?: string;
|
|
11
|
+
}): string;
|
|
12
|
+
/**
|
|
13
|
+
* Create the browser-side loader source fetched by a generated bookmarklet.
|
|
14
|
+
*
|
|
15
|
+
* @param {{browserInjectSource?: string}} [options]
|
|
16
|
+
* @returns {string}
|
|
17
|
+
*/
|
|
18
|
+
export function createBookmarkletLoaderSource(options?: {
|
|
19
|
+
browserInjectSource?: string;
|
|
20
|
+
}): string;
|
|
21
|
+
export const BOOKMARKLET_ERROR_EVENT: "phantomstream:bookmarklet-error";
|
|
22
|
+
//# sourceMappingURL=bookmarklet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bookmarklet.d.ts","sourceRoot":"","sources":["../../../src/adapters/bookmarklet.js"],"names":[],"mappings":"AAmCA;;;;;GAKG;AACH,iDAHW;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAC,GAClD,MAAM,CA6BlB;AAED;;;;;GAKG;AACH,wDAHW;IAAC,mBAAmB,CAAC,EAAE,MAAM,CAAA;CAAC,GAC5B,MAAM,CAuBlB;AAzFD,sCAAuC,iCAAiC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-inject.d.ts","sourceRoot":"","sources":["../../../src/adapters/browser-inject.js"],"names":[],"mappings":"AASA;;;;GAIG;AACH,0CAFa,MAAM,CAIlB"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a Chromium MV3 extension adapter handle.
|
|
3
|
+
*
|
|
4
|
+
* @param {Object} options
|
|
5
|
+
* @param {Object} options.chrome Chromium extension API object.
|
|
6
|
+
* @param {{send?: Function, onMessage?: Function}} [options.transport]
|
|
7
|
+
* @param {string} [options.alarmName]
|
|
8
|
+
* @param {string} [options.storageKey]
|
|
9
|
+
* @param {Object} [options.logger]
|
|
10
|
+
* @param {Function} [options.now]
|
|
11
|
+
* @returns {{
|
|
12
|
+
* install: () => Promise<Object>,
|
|
13
|
+
* dispose: () => void,
|
|
14
|
+
* sendControl: (type: string, payload?: Object) => Promise<void>,
|
|
15
|
+
* getSessionState: () => Object|null
|
|
16
|
+
* }}
|
|
17
|
+
*/
|
|
18
|
+
export function createExtensionAdapter(options: {
|
|
19
|
+
chrome: any;
|
|
20
|
+
transport?: {
|
|
21
|
+
send?: Function;
|
|
22
|
+
onMessage?: Function;
|
|
23
|
+
};
|
|
24
|
+
alarmName?: string;
|
|
25
|
+
storageKey?: string;
|
|
26
|
+
logger?: any;
|
|
27
|
+
now?: Function;
|
|
28
|
+
}): {
|
|
29
|
+
install: () => Promise<any>;
|
|
30
|
+
dispose: () => void;
|
|
31
|
+
sendControl: (type: string, payload?: any) => Promise<void>;
|
|
32
|
+
getSessionState: () => any | null;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Return classic content-script source that bridges capture messages to the
|
|
36
|
+
* MV3 service worker.
|
|
37
|
+
*
|
|
38
|
+
* @returns {string}
|
|
39
|
+
*/
|
|
40
|
+
export function createExtensionContentBridge(): string;
|
|
41
|
+
export const PHANTOMSTREAM_WATCHDOG_ALARM: "phantomstream-watchdog";
|
|
42
|
+
export const PHANTOMSTREAM_SESSION_KEY: "phantomstream:mv3-session";
|
|
43
|
+
//# sourceMappingURL=extension.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extension.d.ts","sourceRoot":"","sources":["../../../src/adapters/extension.js"],"names":[],"mappings":"AAuHA;;;;;;;;;;;;;;;;GAgBG;AACH,gDAbG;IAAwB,MAAM;IAC4B,SAAS,GAA3D;QAAC,IAAI,CAAC,WAAW;QAAC,SAAS,CAAC,WAAU;KAAC;IACtB,SAAS,GAA1B,MAAM;IACW,UAAU,GAA3B,MAAM;IACW,MAAM;IACJ,GAAG;CAC9B,GAAU;IACR,OAAO,EAAE,MAAM,OAAO,KAAQ,CAAC;IAC/B,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,KAAQ,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/D,eAAe,EAAE,MAAM,MAAO,IAAI,CAAA;CACnC,CA+KH;AAED;;;;;GAKG;AACH,gDAFa,MAAM,CAMlB;AA1TD,2CAA4C,wBAAwB,CAAC;AACrE,wCAAyC,2BAA2B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"playwright-inject.d.ts","sourceRoot":"","sources":["../../../src/adapters/playwright-inject.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read the checked-in classic-script inject artifact.
|
|
3
|
+
*
|
|
4
|
+
* @returns {string}
|
|
5
|
+
*/
|
|
6
|
+
export function getPlaywrightInjectSource(options: any): string;
|
|
7
|
+
/**
|
|
8
|
+
* Create a Playwright/CDP adapter for one driven page.
|
|
9
|
+
*
|
|
10
|
+
* @param {Object} options
|
|
11
|
+
* @returns {Object}
|
|
12
|
+
*/
|
|
13
|
+
export function createPlaywrightAdapter(options: any): any;
|
|
14
|
+
//# sourceMappingURL=playwright.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"playwright.d.ts","sourceRoot":"","sources":["../../../src/adapters/playwright.js"],"names":[],"mappings":"AAwBA;;;;GAIG;AACH,yDAFa,MAAM,CAIlB;AA6BD;;;;;GAKG;AACH,2DAydC"}
|