browserpaw 0.0.0-stage → 5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/LICENSE +681 -0
  2. package/README.md +4 -2
  3. package/dist/v5/cli-files.cjs +147 -0
  4. package/dist/v5/cli.cjs +4900 -0
  5. package/dist/v5/extension/assets/popup-Djl4pI1R.css +359 -0
  6. package/dist/v5/extension/background.js +39389 -0
  7. package/dist/v5/extension/browserpaw-build.json +191 -0
  8. package/dist/v5/extension/chunks/popup-BSqTH70w.js +6575 -0
  9. package/dist/v5/extension/content-scripts/agent-cursor.js +1475 -0
  10. package/dist/v5/extension/icon/128.png +0 -0
  11. package/dist/v5/extension/icon/16.png +0 -0
  12. package/dist/v5/extension/icon/32.png +0 -0
  13. package/dist/v5/extension/icon/48.png +0 -0
  14. package/dist/v5/extension/icon/96.png +0 -0
  15. package/dist/v5/extension/images/cursor-chat.png +0 -0
  16. package/dist/v5/extension/inject-scripts/accessibility-tree-helper.js +2031 -0
  17. package/dist/v5/extension/inject-scripts/keyboard-helper.js +412 -0
  18. package/dist/v5/extension/inject-scripts/network-helper.js +378 -0
  19. package/dist/v5/extension/inject-scripts/screenshot-helper.js +449 -0
  20. package/dist/v5/extension/inpage-engine.js +9437 -0
  21. package/dist/v5/extension/manifest.json +1 -0
  22. package/dist/v5/extension/popup.html +14 -0
  23. package/dist/v5/host.cjs +19813 -0
  24. package/dist/v5/recipes/bilibili-popular-videos.json +364 -0
  25. package/dist/v5/recipes/bilibili-video-detail.json +395 -0
  26. package/dist/v5/recipes/developer.mozilla.org.md +15 -0
  27. package/dist/v5/recipes/github-issue-thread.json +313 -0
  28. package/dist/v5/recipes/github-releases.json +218 -0
  29. package/dist/v5/recipes/github-repo-readme.json +306 -0
  30. package/dist/v5/recipes/github-repo-search.json +313 -0
  31. package/dist/v5/recipes/mdn-search.json +219 -0
  32. package/dist/v5/recipes/npm-compare.json +458 -0
  33. package/dist/v5/recipes/reddit-post-read.json +289 -0
  34. package/dist/v5/recipes/reddit-subreddit-posts.json +331 -0
  35. package/dist/v5/recipes/v2ex-node-topics.json +334 -0
  36. package/dist/v5/recipes/v2ex-topic-read.json +325 -0
  37. package/dist/v5/recipes/x-profile-posts.json +332 -0
  38. package/dist/v5/recipes/x-search-thread.json +293 -0
  39. package/dist/v5/recipes/x-visible-thread.json +260 -0
  40. package/dist/v5/recipes/youtube-search-videos.json +279 -0
  41. package/dist/v5/recipes/youtube-video-read.json +349 -0
  42. package/dist/v5/run_host.bat +7 -0
  43. package/dist/v5/run_host.sh +6 -0
  44. package/dist/v5/skill/browserpaw/SKILL.md +48 -0
  45. package/dist/v5/skill/browserpaw/assets/recipes/bilibili-popular-videos.json +364 -0
  46. package/dist/v5/skill/browserpaw/assets/recipes/bilibili-video-detail.json +395 -0
  47. package/dist/v5/skill/browserpaw/assets/recipes/developer.mozilla.org.md +15 -0
  48. package/dist/v5/skill/browserpaw/assets/recipes/github-issue-thread.json +313 -0
  49. package/dist/v5/skill/browserpaw/assets/recipes/github-releases.json +218 -0
  50. package/dist/v5/skill/browserpaw/assets/recipes/github-repo-readme.json +306 -0
  51. package/dist/v5/skill/browserpaw/assets/recipes/github-repo-search.json +313 -0
  52. package/dist/v5/skill/browserpaw/assets/recipes/mdn-search.json +219 -0
  53. package/dist/v5/skill/browserpaw/assets/recipes/npm-compare.json +458 -0
  54. package/dist/v5/skill/browserpaw/assets/recipes/reddit-post-read.json +289 -0
  55. package/dist/v5/skill/browserpaw/assets/recipes/reddit-subreddit-posts.json +331 -0
  56. package/dist/v5/skill/browserpaw/assets/recipes/v2ex-node-topics.json +334 -0
  57. package/dist/v5/skill/browserpaw/assets/recipes/v2ex-topic-read.json +325 -0
  58. package/dist/v5/skill/browserpaw/assets/recipes/x-profile-posts.json +332 -0
  59. package/dist/v5/skill/browserpaw/assets/recipes/x-search-thread.json +293 -0
  60. package/dist/v5/skill/browserpaw/assets/recipes/x-visible-thread.json +260 -0
  61. package/dist/v5/skill/browserpaw/assets/recipes/youtube-search-videos.json +279 -0
  62. package/dist/v5/skill/browserpaw/assets/recipes/youtube-video-read.json +349 -0
  63. package/dist/v5/skill/browserpaw/references/TROUBLESHOOTING.md +7 -0
  64. package/dist/v5/skill/browserpaw/references/TROUBLESHOOTING.zh-CN.md +5 -0
  65. package/dist/v5/skill/browserpaw/references/browser-data.md +33 -0
  66. package/dist/v5/skill/browserpaw/references/commands.md +103 -0
  67. package/dist/v5/skill/browserpaw/references/debugging.md +32 -0
  68. package/dist/v5/skill/browserpaw/references/recipe-contract.md +47 -0
  69. package/package.json +67 -4
@@ -0,0 +1,378 @@
1
+ /**
2
+ * Network Capture Helper
3
+ *
4
+ * This script helps replay network requests with the original cookies and headers.
5
+ */
6
+
7
+ // Prevent duplicate initialization
8
+ if (window.__NETWORK_CAPTURE_HELPER_INITIALIZED__) {
9
+ // Already initialized, skip
10
+ } else {
11
+ window.__NETWORK_CAPTURE_HELPER_INITIALIZED__ = true;
12
+
13
+ const FORBIDDEN_METADATA_IPV4 = new Set([
14
+ '169.254.169.254',
15
+ '169.254.169.253',
16
+ '169.254.170.2',
17
+ '169.254.170.23',
18
+ '169.254.0.2',
19
+ '100.100.100.200',
20
+ ]);
21
+
22
+ const FORBIDDEN_METADATA_HOSTS = new Set([
23
+ 'instance-data',
24
+ 'instance-data.ec2.internal',
25
+ 'metadata.google.internal',
26
+ 'metadata.goog',
27
+ 'metadata.internal',
28
+ ]);
29
+
30
+ function parseIpv6ToGroups(rawHost) {
31
+ const withoutZone = rawHost.split('%')[0];
32
+ if (!withoutZone.includes(':')) return null;
33
+ const halves = withoutZone.split('::');
34
+ if (halves.length > 2) return null;
35
+ const parseSegment = (segment) => {
36
+ if (!segment) return [];
37
+ const parts = segment.split(':');
38
+ const groups = [];
39
+ for (let index = 0; index < parts.length; index++) {
40
+ const token = parts[index];
41
+ if (token.includes('.')) {
42
+ if (index !== parts.length - 1) return null;
43
+ const octets = token.split('.');
44
+ if (octets.length !== 4) return null;
45
+ const nums = [];
46
+ for (const octet of octets) {
47
+ if (!/^\d{1,3}$/.test(octet)) return null;
48
+ const num = Number(octet);
49
+ if (num < 0 || num > 255) return null;
50
+ nums.push(num);
51
+ }
52
+ groups.push((nums[0] << 8) | nums[1], (nums[2] << 8) | nums[3]);
53
+ } else {
54
+ if (!/^[0-9a-f]{1,4}$/i.test(token)) return null;
55
+ groups.push(parseInt(token, 16));
56
+ }
57
+ }
58
+ return groups;
59
+ };
60
+ const left = parseSegment(halves[0]);
61
+ if (!left) return null;
62
+ if (halves.length === 1) return left.length === 8 ? left : null;
63
+ const right = parseSegment(halves[1]);
64
+ if (!right) return null;
65
+ const missing = 8 - (left.length + right.length);
66
+ if (missing < 1) return null;
67
+ return [...left, ...new Array(missing).fill(0), ...right];
68
+ }
69
+
70
+ function isForbiddenTargetUrl(rawUrl) {
71
+ if (!rawUrl || typeof rawUrl !== 'string') return false;
72
+ const trimmed = rawUrl.trim();
73
+ const lower = trimmed.toLowerCase();
74
+ if (
75
+ lower.startsWith('file:') ||
76
+ lower.startsWith('chrome://') ||
77
+ lower.startsWith('edge://') ||
78
+ lower.startsWith('devtools://') ||
79
+ lower.startsWith('chrome-extension://') ||
80
+ lower.startsWith('view-source:')
81
+ ) {
82
+ return true;
83
+ }
84
+ try {
85
+ const parsed = new URL(trimmed);
86
+ const host = parsed.hostname
87
+ .toLowerCase()
88
+ .replace(/^\[|\]$/g, '')
89
+ .replace(/\.+$/, '');
90
+ if (FORBIDDEN_METADATA_IPV4.has(host) || FORBIDDEN_METADATA_HOSTS.has(host)) {
91
+ return true;
92
+ }
93
+ if (
94
+ host.endsWith('.metadata.google.internal') ||
95
+ host.endsWith('.metadata.goog') ||
96
+ host.endsWith('.metadata.internal')
97
+ ) {
98
+ return true;
99
+ }
100
+ const groups = parseIpv6ToGroups(host);
101
+ if (groups) {
102
+ const [g0, g1, g2, g3, g4, g5, g6, g7] = groups;
103
+ if (
104
+ g0 === 0xfd00 &&
105
+ g1 === 0x0ec2 &&
106
+ g2 === 0 &&
107
+ g3 === 0 &&
108
+ g4 === 0 &&
109
+ g5 === 0 &&
110
+ g6 === 0 &&
111
+ g7 === 0x0254
112
+ ) {
113
+ return true;
114
+ }
115
+ const toIpv4 = (hi, lo) =>
116
+ [(hi >>> 8) & 0xff, hi & 0xff, (lo >>> 8) & 0xff, lo & 0xff].join('.');
117
+ if (
118
+ (g0 === 0 && g1 === 0 && g2 === 0 && g3 === 0 && g4 === 0 && g5 === 0xffff) ||
119
+ (g0 === 0 && g1 === 0 && g2 === 0 && g3 === 0 && g4 === 0xffff && g5 === 0) ||
120
+ (g0 === 0 &&
121
+ g1 === 0 &&
122
+ g2 === 0 &&
123
+ g3 === 0 &&
124
+ g4 === 0 &&
125
+ g5 === 0 &&
126
+ (g6 !== 0 || g7 > 1)) ||
127
+ (g0 === 0x0064 && g1 === 0xff9b && g2 === 0 && g3 === 0 && g4 === 0 && g5 === 0)
128
+ ) {
129
+ return FORBIDDEN_METADATA_IPV4.has(toIpv4(g6, g7));
130
+ }
131
+ if (g0 === 0x2002) {
132
+ return FORBIDDEN_METADATA_IPV4.has(toIpv4(g1, g2));
133
+ }
134
+ }
135
+ return false;
136
+ } catch {
137
+ return false;
138
+ }
139
+ }
140
+
141
+ /**
142
+ * Replay a network request
143
+ * @param {string} url - The URL to send the request to
144
+ * @param {string} method - The HTTP method to use
145
+ * @param {Object} headers - The headers to include in the request
146
+ * @param {any} body - The body of the request
147
+ * @param {number} timeout - Timeout in milliseconds (default: 30000)
148
+ * @returns {Promise<Object>} - The response data
149
+ */
150
+ async function replayNetworkRequest(
151
+ url,
152
+ method,
153
+ headers,
154
+ body,
155
+ timeout = 30000,
156
+ formDataDescriptor = null,
157
+ ) {
158
+ try {
159
+ // Create fetch options
160
+ const options = {
161
+ method: method,
162
+ headers: headers || {},
163
+ credentials: 'include', // Include cookies
164
+ mode: 'cors',
165
+ cache: 'no-cache',
166
+ };
167
+
168
+ // Helper: convert base64 to Blob
169
+ const base64ToBlob = (base64, contentType = 'application/octet-stream') => {
170
+ try {
171
+ const decodedString = atob(base64);
172
+ const len = decodedString.length;
173
+ const bytes = new Uint8Array(len);
174
+ for (let i = 0; i < len; i++) bytes[i] = decodedString.charCodeAt(i);
175
+ return new Blob([bytes], { type: contentType });
176
+ } catch (e) {
177
+ return new Blob([]);
178
+ }
179
+ };
180
+
181
+ // Build multipart/form-data if descriptor is provided
182
+ if (method !== 'GET' && method !== 'HEAD' && formDataDescriptor) {
183
+ const fd = new FormData();
184
+ try {
185
+ if (Array.isArray(formDataDescriptor)) {
186
+ for (const item of formDataDescriptor) {
187
+ if (!Array.isArray(item) || item.length < 2) continue;
188
+ const name = String(item[0] || 'file');
189
+ const spec = String(item[1] || '');
190
+ const filenameHint = item[2] ? String(item[2]) : undefined;
191
+ if (/^(https?:\/\/|url:)/i.test(spec)) {
192
+ const url = spec.replace(/^url:/i, '');
193
+ if (isForbiddenTargetUrl(url)) {
194
+ throw new Error(
195
+ 'Security Restriction: Navigation or requests to cloud instance metadata service are strictly forbidden.',
196
+ );
197
+ }
198
+ const resp = await fetch(url);
199
+ if (isForbiddenTargetUrl(resp.url)) {
200
+ throw new Error(
201
+ 'Security Restriction: Redirect to cloud instance metadata or restricted URL is strictly forbidden.',
202
+ );
203
+ }
204
+ const blob = await resp.blob();
205
+ const fn =
206
+ filenameHint || url.split('?')[0].split('#')[0].split('/').pop() || 'file';
207
+ fd.append(name, blob, fn);
208
+ } else if (/^base64:/i.test(spec)) {
209
+ const b64 = spec.replace(/^base64:/i, '');
210
+ const blob = base64ToBlob(b64);
211
+ fd.append(name, blob, filenameHint || 'file');
212
+ } else {
213
+ // treat as string field
214
+ fd.append(name, spec);
215
+ }
216
+ }
217
+ } else if (typeof formDataDescriptor === 'object') {
218
+ const fds = formDataDescriptor;
219
+ const fields = fds.fields || {};
220
+ const files = Array.isArray(fds.files) ? fds.files : [];
221
+ for (const [k, v] of Object.entries(fields)) fd.append(String(k), String(v));
222
+ for (const file of files) {
223
+ const name = String(file.name || 'file');
224
+ if (file.fileUrl) {
225
+ const targetFileUrl = String(file.fileUrl);
226
+ if (isForbiddenTargetUrl(targetFileUrl)) {
227
+ throw new Error(
228
+ 'Security Restriction: Navigation or requests to cloud instance metadata service are strictly forbidden.',
229
+ );
230
+ }
231
+ const resp = await fetch(targetFileUrl);
232
+ if (isForbiddenTargetUrl(resp.url)) {
233
+ throw new Error(
234
+ 'Security Restriction: Redirect to cloud instance metadata or restricted URL is strictly forbidden.',
235
+ );
236
+ }
237
+ const blob = await resp.blob();
238
+ const fn =
239
+ file.filename ||
240
+ String(file.fileUrl).split('?')[0].split('#')[0].split('/').pop() ||
241
+ 'file';
242
+ fd.append(name, blob, fn);
243
+ } else if (typeof file.base64Data === 'string') {
244
+ const blob = base64ToBlob(
245
+ String(file.base64Data),
246
+ String(file.contentType || 'application/octet-stream'),
247
+ );
248
+ fd.append(name, blob, file.filename || 'file');
249
+ }
250
+ }
251
+ }
252
+ } catch (e) {
253
+ if (e instanceof Error && e.message.startsWith('Security Restriction:')) {
254
+ throw e;
255
+ }
256
+ console.warn('Failed to construct FormData:', e);
257
+ }
258
+ // Let browser set the correct multipart boundary
259
+ try {
260
+ if (options.headers) {
261
+ delete options.headers['content-type'];
262
+ delete options.headers['Content-Type'];
263
+ }
264
+ } catch {}
265
+ options.body = fd;
266
+ } else if (method !== 'GET' && method !== 'HEAD' && body !== undefined) {
267
+ // Fallback to raw body
268
+ options.body = body;
269
+ }
270
+
271
+ // Create a fetch request with timeout
272
+ const fetchWithTimeout = async (url, options, timeout) => {
273
+ const controller = new AbortController();
274
+ const signal = controller.signal;
275
+
276
+ // Set up abort timeout
277
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
278
+
279
+ try {
280
+ const response = await fetch(url, { ...options, signal });
281
+ clearTimeout(timeoutId);
282
+ return response;
283
+ } catch (error) {
284
+ clearTimeout(timeoutId);
285
+ throw error;
286
+ }
287
+ };
288
+
289
+ // Send request with timeout controller
290
+ const response = await fetchWithTimeout(url, options, timeout);
291
+
292
+ if (isForbiddenTargetUrl(response.url)) {
293
+ return {
294
+ success: false,
295
+ error:
296
+ 'Security Restriction: Redirect to cloud instance metadata service (' +
297
+ response.url +
298
+ ') is strictly forbidden.',
299
+ };
300
+ }
301
+
302
+ // Process response
303
+ const responseData = {
304
+ status: response.status,
305
+ statusText: response.statusText,
306
+ ...(response.url ? { url: response.url } : {}),
307
+ headers: {},
308
+ };
309
+
310
+ // Get response headers
311
+ response.headers.forEach((value, key) => {
312
+ responseData.headers[key] = value;
313
+ });
314
+
315
+ // Try to get response body based on content type
316
+ const contentType = response.headers.get('content-type') || '';
317
+
318
+ try {
319
+ if (contentType.includes('application/json')) {
320
+ responseData.body = await response.json();
321
+ } else if (
322
+ contentType.includes('text/') ||
323
+ contentType.includes('application/xml') ||
324
+ contentType.includes('application/javascript')
325
+ ) {
326
+ responseData.body = await response.text();
327
+ } else {
328
+ // For binary data, just indicate it was received but not parsed
329
+ responseData.body = '[Binary data not displayed]';
330
+ }
331
+ } catch (error) {
332
+ responseData.body = `[Error parsing response body: ${error.message}]`;
333
+ }
334
+
335
+ return {
336
+ success: true,
337
+ response: responseData,
338
+ };
339
+ } catch (error) {
340
+ console.error('Error replaying request:', error);
341
+ return {
342
+ success: false,
343
+ error: `Error replaying request: ${error.message}`,
344
+ };
345
+ }
346
+ }
347
+
348
+ // Listen for messages from the extension
349
+ chrome.runtime.onMessage.addListener((request, _sender, sendResponse) => {
350
+ if (!request || typeof request !== 'object') return false;
351
+ // Respond to ping message
352
+ if (
353
+ request.action === 'chrome_network_request_ping' ||
354
+ String(request.action || '').startsWith('mcp_ping_')
355
+ ) {
356
+ sendResponse({ status: 'pong' });
357
+ return false; // Synchronous response
358
+ } else if (request.action === 'sendPureNetworkRequest') {
359
+ replayNetworkRequest(
360
+ request.url,
361
+ request.method,
362
+ request.headers,
363
+ request.body,
364
+ request.timeout,
365
+ request.formData,
366
+ )
367
+ .then(sendResponse)
368
+ .catch((error) => {
369
+ sendResponse({
370
+ success: false,
371
+ error: `Unexpected error: ${error.message}`,
372
+ });
373
+ });
374
+ return true; // Indicates async response
375
+ }
376
+ return false;
377
+ });
378
+ }