browserwire 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.
@@ -0,0 +1,277 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>BrowserWire</title>
7
+ <style>
8
+ :root {
9
+ --bg: #f4f1ea;
10
+ --panel: #fffaf0;
11
+ --text: #222;
12
+ --muted: #5f5a4d;
13
+ --ok: #2f7d32;
14
+ --warn: #915f00;
15
+ --err: #b3261e;
16
+ --border: #ded7c8;
17
+ }
18
+
19
+ * {
20
+ box-sizing: border-box;
21
+ }
22
+
23
+ body {
24
+ margin: 0;
25
+ font:
26
+ 14px/1.4 "Georgia",
27
+ "Times New Roman",
28
+ serif;
29
+ color: var(--text);
30
+ background: radial-gradient(circle at top, #fffaf0 0%, var(--bg) 70%);
31
+ }
32
+
33
+ .wrap {
34
+ padding: 14px;
35
+ }
36
+
37
+ .card {
38
+ background: var(--panel);
39
+ border: 1px solid var(--border);
40
+ border-radius: 10px;
41
+ padding: 12px;
42
+ box-shadow: 0 5px 14px rgba(0, 0, 0, 0.06);
43
+ }
44
+
45
+ h1 {
46
+ margin: 0 0 8px;
47
+ font-size: 16px;
48
+ }
49
+
50
+ .row {
51
+ display: flex;
52
+ gap: 8px;
53
+ margin: 10px 0;
54
+ }
55
+
56
+ input,
57
+ button {
58
+ font: inherit;
59
+ }
60
+
61
+ input {
62
+ width: 100%;
63
+ border: 1px solid var(--border);
64
+ border-radius: 8px;
65
+ padding: 8px;
66
+ background: #fff;
67
+ }
68
+
69
+ button {
70
+ border: 1px solid #8f8572;
71
+ background: #ece2cd;
72
+ border-radius: 8px;
73
+ padding: 8px 10px;
74
+ cursor: pointer;
75
+ }
76
+
77
+ button.primary {
78
+ background: #2f7d32;
79
+ color: #fff;
80
+ border-color: #256b28;
81
+ }
82
+
83
+ button.checkpoint {
84
+ background: #5c6bc0;
85
+ color: #fff;
86
+ border-color: #4a57a8;
87
+ }
88
+
89
+ button.danger {
90
+ background: #b3261e;
91
+ color: #fff;
92
+ border-color: #8e1e18;
93
+ }
94
+
95
+ #checkpointNote {
96
+ width: 100%;
97
+ border: 1px solid var(--border);
98
+ border-radius: 8px;
99
+ padding: 8px;
100
+ background: #fff;
101
+ font: inherit;
102
+ font-size: 13px;
103
+ resize: vertical;
104
+ min-height: 48px;
105
+ display: none;
106
+ }
107
+
108
+ #checkpointNote.visible {
109
+ display: block;
110
+ }
111
+
112
+ #checkpointOverlay {
113
+ display: none;
114
+ position: fixed;
115
+ inset: 0;
116
+ background: rgba(255, 250, 240, 0.9);
117
+ z-index: 999;
118
+ flex-direction: column;
119
+ align-items: center;
120
+ justify-content: center;
121
+ gap: 12px;
122
+ }
123
+
124
+ #checkpointOverlay.visible {
125
+ display: flex;
126
+ }
127
+
128
+ .overlay-spinner {
129
+ width: 32px;
130
+ height: 32px;
131
+ border: 3px solid var(--border);
132
+ border-top-color: #5c6bc0;
133
+ border-radius: 50%;
134
+ animation: spin 0.8s linear infinite;
135
+ }
136
+
137
+ @keyframes spin {
138
+ to { transform: rotate(360deg); }
139
+ }
140
+
141
+ .overlay-text {
142
+ font-size: 14px;
143
+ color: var(--muted);
144
+ }
145
+
146
+ #backendStatus,
147
+ #sessionStatus {
148
+ margin: 6px 0;
149
+ }
150
+
151
+ .ok {
152
+ color: var(--ok);
153
+ }
154
+
155
+ .warn {
156
+ color: var(--warn);
157
+ }
158
+
159
+ .err {
160
+ color: var(--err);
161
+ }
162
+
163
+ .stats {
164
+ margin: 8px 0;
165
+ padding: 8px;
166
+ background: #fff;
167
+ border: 1px solid var(--border);
168
+ border-radius: 8px;
169
+ font-size: 13px;
170
+ display: none;
171
+ }
172
+
173
+ .stats.visible {
174
+ display: block;
175
+ }
176
+
177
+ .stats .stat-row {
178
+ display: flex;
179
+ justify-content: space-between;
180
+ padding: 2px 0;
181
+ }
182
+
183
+ .stats .stat-label {
184
+ color: var(--muted);
185
+ }
186
+
187
+ .stats .stat-value {
188
+ font-weight: bold;
189
+ }
190
+
191
+ pre {
192
+ margin: 10px 0 0;
193
+ border: 1px solid var(--border);
194
+ border-radius: 8px;
195
+ padding: 8px;
196
+ height: 200px;
197
+ overflow: auto;
198
+ background: #fff;
199
+ font-family: "Menlo", "Consolas", monospace;
200
+ font-size: 12px;
201
+ }
202
+
203
+ #apiStatus {
204
+ margin: 8px 0;
205
+ padding: 8px;
206
+ background: #e8f5e9;
207
+ border: 1px solid var(--border);
208
+ border-radius: 8px;
209
+ font-size: 13px;
210
+ display: none;
211
+ }
212
+
213
+ #apiStatus a {
214
+ color: var(--ok);
215
+ font-weight: bold;
216
+ }
217
+ </style>
218
+ </head>
219
+ <body>
220
+ <div class="wrap">
221
+ <div class="card">
222
+ <h1>BrowserWire</h1>
223
+ <label for="wsUrl">Backend URL</label>
224
+ <div class="row">
225
+ <input id="wsUrl" type="text" value="ws://127.0.0.1:8787" />
226
+ </div>
227
+ <div class="row">
228
+ <button id="connect">Connect Backend</button>
229
+ <button id="disconnect">Disconnect Backend</button>
230
+ </div>
231
+ <div class="row">
232
+ <button id="startExploring" class="primary">Start Exploring</button>
233
+ <button id="stopExploring" class="danger">Stop Exploring</button>
234
+ </div>
235
+ <div class="row" id="checkpointRow" style="display:none">
236
+ <button id="checkpoint" class="checkpoint">Checkpoint</button>
237
+ </div>
238
+ <textarea id="checkpointNote" placeholder="Optional: describe what you just explored..."></textarea>
239
+ <div id="backendStatus" class="warn">Backend: Disconnected</div>
240
+ <div id="sessionStatus" class="warn">Session: Idle</div>
241
+ <div id="siteOrigin" style="display:none; margin:4px 0; font-size:13px; color:var(--muted)"></div>
242
+ <div id="sessionStats" class="stats">
243
+ <div class="stat-row">
244
+ <span class="stat-label">Snapshots</span>
245
+ <span class="stat-value" id="statSnapshots">0</span>
246
+ </div>
247
+ <div class="stat-row">
248
+ <span class="stat-label">Entities</span>
249
+ <span class="stat-value" id="statEntities">0</span>
250
+ </div>
251
+ <div class="stat-row">
252
+ <span class="stat-label">Actions</span>
253
+ <span class="stat-value" id="statActions">0</span>
254
+ </div>
255
+ <div class="stat-row">
256
+ <span class="stat-label">Views</span>
257
+ <span class="stat-value" id="statViews">0</span>
258
+ </div>
259
+ <div class="stat-row" id="statBufferedRow">
260
+ <span class="stat-label">Buffered</span>
261
+ <span class="stat-value" id="statBuffered">0</span>
262
+ </div>
263
+ </div>
264
+ <div id="apiStatus"></div>
265
+
266
+ <pre id="log" aria-live="polite"></pre>
267
+ </div>
268
+ </div>
269
+
270
+ <!-- Blocking overlay shown while checkpoint is processing -->
271
+ <div id="checkpointOverlay">
272
+ <div class="overlay-spinner"></div>
273
+ <div class="overlay-text">Processing checkpoint…</div>
274
+ </div>
275
+ <script type="module" src="sidepanel.js"></script>
276
+ </body>
277
+ </html>
@@ -0,0 +1,211 @@
1
+ const backendStatusNode = document.querySelector("#backendStatus");
2
+ const sessionStatusNode = document.querySelector("#sessionStatus");
3
+ const sessionStatsNode = document.querySelector("#sessionStats");
4
+ const wsUrlInput = document.querySelector("#wsUrl");
5
+ const logNode = document.querySelector("#log");
6
+
7
+ const connectButton = document.querySelector("#connect");
8
+ const disconnectButton = document.querySelector("#disconnect");
9
+ const startExploringButton = document.querySelector("#startExploring");
10
+ const stopExploringButton = document.querySelector("#stopExploring");
11
+ const checkpointButton = document.querySelector("#checkpoint");
12
+ const checkpointRow = document.querySelector("#checkpointRow");
13
+ const checkpointNoteInput = document.querySelector("#checkpointNote");
14
+ const checkpointOverlay = document.querySelector("#checkpointOverlay");
15
+ const apiStatusNode = document.querySelector("#apiStatus");
16
+
17
+ const siteOriginNode = document.querySelector("#siteOrigin");
18
+ const statSnapshots = document.querySelector("#statSnapshots");
19
+ const statEntities = document.querySelector("#statEntities");
20
+ const statActions = document.querySelector("#statActions");
21
+ const statViews = document.querySelector("#statViews");
22
+ const statBuffered = document.querySelector("#statBuffered");
23
+
24
+ const setLineStatus = (node, text, level) => {
25
+ node.textContent = text;
26
+ node.className = level;
27
+ };
28
+
29
+ const log = (message) => {
30
+ const now = new Date().toLocaleTimeString();
31
+ logNode.textContent = `[${now}] ${message}\n${logNode.textContent}`;
32
+ };
33
+
34
+ const mapLevel = (state) => {
35
+ if (state === "connected") {
36
+ return "ok";
37
+ }
38
+
39
+ if (state === "disconnected") {
40
+ return "warn";
41
+ }
42
+
43
+ return "warn";
44
+ };
45
+
46
+ const renderState = (state) => {
47
+ if (!state) {
48
+ return;
49
+ }
50
+
51
+ if (typeof state.wsUrl === "string" && state.wsUrl.length > 0) {
52
+ wsUrlInput.value = state.wsUrl;
53
+ }
54
+
55
+ const backendState = state.backendState || "disconnected";
56
+ setLineStatus(
57
+ backendStatusNode,
58
+ `Backend: ${backendState}`,
59
+ mapLevel(backendState)
60
+ );
61
+
62
+ if (state.session && state.session.sessionId) {
63
+ const session = state.session;
64
+ setLineStatus(
65
+ sessionStatusNode,
66
+ `Session: exploring (${session.snapshotCount || 0} snapshots)`,
67
+ "ok"
68
+ );
69
+
70
+ // Show site origin
71
+ try {
72
+ const origin = new URL(session.url).origin;
73
+ siteOriginNode.textContent = `Site: ${origin}`;
74
+ siteOriginNode.style.display = "";
75
+ } catch {
76
+ siteOriginNode.style.display = "none";
77
+ }
78
+
79
+ statSnapshots.textContent = session.snapshotCount || 0;
80
+ statEntities.textContent = session.entityCount || 0;
81
+ statActions.textContent = session.actionCount || 0;
82
+ statViews.textContent = session.viewCount || 0;
83
+ sessionStatsNode.classList.add("visible");
84
+
85
+ // Show checkpoint controls during active session
86
+ checkpointRow.style.display = "";
87
+ checkpointNoteInput.classList.add("visible");
88
+ } else {
89
+ setLineStatus(sessionStatusNode, "Session: Idle", "warn");
90
+ siteOriginNode.style.display = "none";
91
+ sessionStatsNode.classList.remove("visible");
92
+
93
+ // Hide checkpoint controls when idle
94
+ checkpointRow.style.display = "none";
95
+ checkpointNoteInput.classList.remove("visible");
96
+ }
97
+ };
98
+
99
+ const sendBackgroundCommand = async (command, payload = {}) => {
100
+ const response = await chrome.runtime.sendMessage({
101
+ source: "sidepanel",
102
+ command,
103
+ ...payload
104
+ });
105
+
106
+ if (!response) {
107
+ throw new Error("No response from background service worker");
108
+ }
109
+
110
+ if (response.state) {
111
+ renderState(response.state);
112
+ }
113
+
114
+ if (response.ok !== true) {
115
+ throw new Error(response.error || "Command failed");
116
+ }
117
+
118
+ return response;
119
+ };
120
+
121
+ connectButton.addEventListener("click", async () => {
122
+ try {
123
+ await sendBackgroundCommand("connect_backend", {
124
+ url: wsUrlInput.value.trim()
125
+ });
126
+ log("Requested backend connect");
127
+ } catch (error) {
128
+ log(`Connect failed: ${error.message}`);
129
+ }
130
+ });
131
+
132
+ disconnectButton.addEventListener("click", async () => {
133
+ try {
134
+ await sendBackgroundCommand("disconnect_backend");
135
+ log("Requested backend disconnect");
136
+ } catch (error) {
137
+ log(`Disconnect failed: ${error.message}`);
138
+ }
139
+ });
140
+
141
+ startExploringButton.addEventListener("click", async () => {
142
+ try {
143
+ const response = await sendBackgroundCommand("start_exploring");
144
+ log(`Exploration started: ${response.sessionId}`);
145
+ } catch (error) {
146
+ log(`Start exploring failed: ${error.message}`);
147
+ }
148
+ });
149
+
150
+ stopExploringButton.addEventListener("click", async () => {
151
+ try {
152
+ await sendBackgroundCommand("stop_exploring");
153
+ log("Exploration stopped");
154
+ } catch (error) {
155
+ log(`Stop exploring failed: ${error.message}`);
156
+ }
157
+ });
158
+
159
+ checkpointButton.addEventListener("click", async () => {
160
+ const note = checkpointNoteInput.value.trim();
161
+ try {
162
+ await sendBackgroundCommand("checkpoint", { note });
163
+ log(`Checkpoint triggered${note ? `: "${note}"` : ""}`);
164
+ } catch (error) {
165
+ log(`Checkpoint failed: ${error.message}`);
166
+ }
167
+ });
168
+
169
+ const showApiStatus = () => {
170
+ apiStatusNode.style.display = "block";
171
+ apiStatusNode.innerHTML = 'API ready at <a href="http://127.0.0.1:8787/api/docs" target="_blank">http://127.0.0.1:8787/api/docs</a>';
172
+ };
173
+
174
+ chrome.runtime.onMessage.addListener((message) => {
175
+ if (!message || message.source !== "background") {
176
+ return;
177
+ }
178
+
179
+ if (message.event === "state") {
180
+ renderState(message.state);
181
+ return;
182
+ }
183
+
184
+ if (message.event === "log" && message.line) {
185
+ log(message.line);
186
+ return;
187
+ }
188
+
189
+ if (message.event === "manifest_ready") {
190
+ showApiStatus();
191
+ }
192
+
193
+ if (message.event === "checkpoint_started") {
194
+ checkpointOverlay.classList.add("visible");
195
+ }
196
+
197
+ if (message.event === "checkpoint_complete") {
198
+ checkpointOverlay.classList.remove("visible");
199
+ checkpointNoteInput.value = "";
200
+ showApiStatus();
201
+ log(`Checkpoint complete${message.checkpointIndex !== undefined ? ` (${message.checkpointIndex})` : ""}`);
202
+ }
203
+
204
+ if (message.event === "buffered") {
205
+ if (statBuffered) statBuffered.textContent = message.count || 0;
206
+ }
207
+ });
208
+
209
+ sendBackgroundCommand("get_state").catch((error) => {
210
+ log(`Unable to fetch initial state: ${error.message}`);
211
+ });
@@ -0,0 +1,22 @@
1
+ The file `rrweb-record.min.js` is bundled from the @rrweb/record package
2
+ (https://github.com/rrweb-io/rrweb), which is licensed under the MIT License.
3
+
4
+ Copyright (c) 2018 ��逸 (SmartX)
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.