browserpaw 5.0.0 → 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 (50) hide show
  1. package/dist/v5/cli.cjs +1207 -335
  2. package/dist/v5/extension/background.js +8649 -6972
  3. package/dist/v5/extension/browserpaw-build.json +52 -45
  4. package/dist/v5/extension/chunks/{popup-DjxqduQH.js → popup-BSqTH70w.js} +39 -6
  5. package/dist/v5/extension/content-scripts/agent-cursor.js +30 -14
  6. package/dist/v5/extension/inject-scripts/accessibility-tree-helper.js +377 -229
  7. package/dist/v5/extension/inject-scripts/keyboard-helper.js +12 -2
  8. package/dist/v5/extension/inject-scripts/network-helper.js +166 -1
  9. package/dist/v5/extension/inject-scripts/screenshot-helper.js +397 -356
  10. package/dist/v5/extension/inpage-engine.js +7070 -6933
  11. package/dist/v5/extension/manifest.json +1 -1
  12. package/dist/v5/extension/popup.html +1 -1
  13. package/dist/v5/host.cjs +445 -73
  14. package/dist/v5/recipes/bilibili-popular-videos.json +364 -0
  15. package/dist/v5/recipes/bilibili-video-detail.json +395 -0
  16. package/dist/v5/recipes/github-issue-thread.json +313 -0
  17. package/dist/v5/recipes/github-releases.json +86 -45
  18. package/dist/v5/recipes/github-repo-readme.json +306 -0
  19. package/dist/v5/recipes/github-repo-search.json +313 -0
  20. package/dist/v5/recipes/mdn-search.json +93 -48
  21. package/dist/v5/recipes/npm-compare.json +6 -4
  22. package/dist/v5/recipes/reddit-post-read.json +289 -0
  23. package/dist/v5/recipes/reddit-subreddit-posts.json +331 -0
  24. package/dist/v5/recipes/v2ex-node-topics.json +334 -0
  25. package/dist/v5/recipes/v2ex-topic-read.json +325 -0
  26. package/dist/v5/recipes/x-profile-posts.json +332 -0
  27. package/dist/v5/recipes/x-search-thread.json +13 -41
  28. package/dist/v5/recipes/x-visible-thread.json +40 -83
  29. package/dist/v5/recipes/youtube-search-videos.json +279 -0
  30. package/dist/v5/recipes/youtube-video-read.json +349 -0
  31. package/dist/v5/skill/browserpaw/SKILL.md +4 -4
  32. package/dist/v5/skill/browserpaw/assets/recipes/bilibili-popular-videos.json +364 -0
  33. package/dist/v5/skill/browserpaw/assets/recipes/bilibili-video-detail.json +395 -0
  34. package/dist/v5/skill/browserpaw/assets/recipes/github-issue-thread.json +313 -0
  35. package/dist/v5/skill/browserpaw/assets/recipes/github-releases.json +86 -45
  36. package/dist/v5/skill/browserpaw/assets/recipes/github-repo-readme.json +306 -0
  37. package/dist/v5/skill/browserpaw/assets/recipes/github-repo-search.json +313 -0
  38. package/dist/v5/skill/browserpaw/assets/recipes/mdn-search.json +93 -48
  39. package/dist/v5/skill/browserpaw/assets/recipes/npm-compare.json +6 -4
  40. package/dist/v5/skill/browserpaw/assets/recipes/reddit-post-read.json +289 -0
  41. package/dist/v5/skill/browserpaw/assets/recipes/reddit-subreddit-posts.json +331 -0
  42. package/dist/v5/skill/browserpaw/assets/recipes/v2ex-node-topics.json +334 -0
  43. package/dist/v5/skill/browserpaw/assets/recipes/v2ex-topic-read.json +325 -0
  44. package/dist/v5/skill/browserpaw/assets/recipes/x-profile-posts.json +332 -0
  45. package/dist/v5/skill/browserpaw/assets/recipes/x-search-thread.json +13 -41
  46. package/dist/v5/skill/browserpaw/assets/recipes/x-visible-thread.json +40 -83
  47. package/dist/v5/skill/browserpaw/assets/recipes/youtube-search-videos.json +279 -0
  48. package/dist/v5/skill/browserpaw/assets/recipes/youtube-video-read.json +349 -0
  49. package/dist/v5/skill/browserpaw/references/recipe-contract.md +4 -3
  50. package/package.json +1 -1
@@ -363,17 +363,27 @@ if (window.__KEYBOARD_HELPER_INITIALIZED__) {
363
363
 
364
364
  // Listener for messages from the extension
365
365
  chrome.runtime.onMessage.addListener((request, _sender, sendResponse) => {
366
+ if (!request || typeof request !== 'object') return false;
366
367
  if (request.action === 'simulateKeyboard') {
367
368
  let targetEl = null;
368
369
  if (request.selector) {
369
- targetEl = document.querySelector(request.selector);
370
+ try {
371
+ targetEl = document.querySelector(request.selector);
372
+ } catch (error) {
373
+ sendResponse({
374
+ success: false,
375
+ error: `Invalid selector "${request.selector}": ${error?.message || String(error)}`,
376
+ results: [],
377
+ });
378
+ return false;
379
+ }
370
380
  if (!targetEl) {
371
381
  sendResponse({
372
382
  success: false,
373
383
  error: `Element with selector "${request.selector}" not found`,
374
384
  results: [],
375
385
  });
376
- return true; // Keep channel open for async response
386
+ return false; // Synchronous response
377
387
  }
378
388
  }
379
389
 
@@ -10,6 +10,134 @@ if (window.__NETWORK_CAPTURE_HELPER_INITIALIZED__) {
10
10
  } else {
11
11
  window.__NETWORK_CAPTURE_HELPER_INITIALIZED__ = true;
12
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
+
13
141
  /**
14
142
  * Replay a network request
15
143
  * @param {string} url - The URL to send the request to
@@ -62,7 +190,17 @@ if (window.__NETWORK_CAPTURE_HELPER_INITIALIZED__) {
62
190
  const filenameHint = item[2] ? String(item[2]) : undefined;
63
191
  if (/^(https?:\/\/|url:)/i.test(spec)) {
64
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
+ }
65
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
+ }
66
204
  const blob = await resp.blob();
67
205
  const fn =
68
206
  filenameHint || url.split('?')[0].split('#')[0].split('/').pop() || 'file';
@@ -84,7 +222,18 @@ if (window.__NETWORK_CAPTURE_HELPER_INITIALIZED__) {
84
222
  for (const file of files) {
85
223
  const name = String(file.name || 'file');
86
224
  if (file.fileUrl) {
87
- const resp = await fetch(String(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
+ }
88
237
  const blob = await resp.blob();
89
238
  const fn =
90
239
  file.filename ||
@@ -101,6 +250,9 @@ if (window.__NETWORK_CAPTURE_HELPER_INITIALIZED__) {
101
250
  }
102
251
  }
103
252
  } catch (e) {
253
+ if (e instanceof Error && e.message.startsWith('Security Restriction:')) {
254
+ throw e;
255
+ }
104
256
  console.warn('Failed to construct FormData:', e);
105
257
  }
106
258
  // Let browser set the correct multipart boundary
@@ -137,10 +289,21 @@ if (window.__NETWORK_CAPTURE_HELPER_INITIALIZED__) {
137
289
  // Send request with timeout controller
138
290
  const response = await fetchWithTimeout(url, options, timeout);
139
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
+
140
302
  // Process response
141
303
  const responseData = {
142
304
  status: response.status,
143
305
  statusText: response.statusText,
306
+ ...(response.url ? { url: response.url } : {}),
144
307
  headers: {},
145
308
  };
146
309
 
@@ -184,6 +347,7 @@ if (window.__NETWORK_CAPTURE_HELPER_INITIALIZED__) {
184
347
 
185
348
  // Listen for messages from the extension
186
349
  chrome.runtime.onMessage.addListener((request, _sender, sendResponse) => {
350
+ if (!request || typeof request !== 'object') return false;
187
351
  // Respond to ping message
188
352
  if (
189
353
  request.action === 'chrome_network_request_ping' ||
@@ -209,5 +373,6 @@ if (window.__NETWORK_CAPTURE_HELPER_INITIALIZED__) {
209
373
  });
210
374
  return true; // Indicates async response
211
375
  }
376
+ return false;
212
377
  });
213
378
  }