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
@@ -0,0 +1,364 @@
1
+ {
2
+ "id": "bilibili-popular-videos",
3
+ "name": "Bilibili popular videos reader",
4
+ "description": "Read Bilibili's trending popular videos via Bilibili's web-interface API inside Chrome with browser cookies and Referer.",
5
+ "source": {
6
+ "type": "builtin",
7
+ "urls": [
8
+ "https://www.bilibili.com/v/popular/all",
9
+ "https://api.bilibili.com/x/web-interface/popular?ps=10&pn=1"
10
+ ]
11
+ },
12
+ "domains": [
13
+ "www.bilibili.com",
14
+ "m.bilibili.com",
15
+ "bilibili.com",
16
+ "api.bilibili.com"
17
+ ],
18
+ "keywords": [
19
+ "bilibili",
20
+ "b站",
21
+ "哔哩哔哩",
22
+ "popular",
23
+ "trending",
24
+ "hot",
25
+ "videos",
26
+ "热门",
27
+ "热榜",
28
+ "视频",
29
+ "B站热门",
30
+ "哔哩哔哩热门",
31
+ "B站视频"
32
+ ],
33
+ "startUrl": "https://www.bilibili.com/v/popular/all",
34
+ "inputSchema": {
35
+ "type": "object",
36
+ "properties": {
37
+ "limit": {
38
+ "type": "integer",
39
+ "minimum": 1,
40
+ "maximum": 20,
41
+ "default": 10
42
+ },
43
+ "page": {
44
+ "type": "integer",
45
+ "minimum": 1,
46
+ "maximum": 10,
47
+ "default": 1
48
+ }
49
+ },
50
+ "required": [],
51
+ "additionalProperties": false
52
+ },
53
+ "outputSchema": {
54
+ "oneOf": [
55
+ {
56
+ "type": "object",
57
+ "properties": {
58
+ "success": {
59
+ "const": true
60
+ },
61
+ "status": {
62
+ "const": "ok"
63
+ },
64
+ "page": {
65
+ "type": "integer",
66
+ "minimum": 1
67
+ },
68
+ "videos": {
69
+ "type": "array",
70
+ "minItems": 1,
71
+ "maxItems": 20,
72
+ "items": {
73
+ "type": "object",
74
+ "properties": {
75
+ "bvid": {
76
+ "type": "string",
77
+ "pattern": "^BV[0-9A-Za-z]+$"
78
+ },
79
+ "title": {
80
+ "type": "string",
81
+ "minLength": 1
82
+ },
83
+ "url": {
84
+ "type": "string",
85
+ "pattern": "^https://www\\.bilibili\\.com/video/BV[0-9A-Za-z]+$"
86
+ },
87
+ "author": {
88
+ "type": "string"
89
+ },
90
+ "category": {
91
+ "type": "string"
92
+ },
93
+ "durationSeconds": {
94
+ "type": "integer",
95
+ "minimum": 0
96
+ },
97
+ "views": {
98
+ "type": "integer",
99
+ "minimum": 0
100
+ },
101
+ "likes": {
102
+ "type": "integer",
103
+ "minimum": 0
104
+ },
105
+ "danmaku": {
106
+ "type": "integer",
107
+ "minimum": 0
108
+ },
109
+ "publishedAt": {
110
+ "type": "integer",
111
+ "minimum": 0
112
+ }
113
+ },
114
+ "required": [
115
+ "bvid",
116
+ "title",
117
+ "url",
118
+ "author",
119
+ "category",
120
+ "durationSeconds",
121
+ "views",
122
+ "likes",
123
+ "danmaku",
124
+ "publishedAt"
125
+ ],
126
+ "additionalProperties": false
127
+ }
128
+ },
129
+ "sources": {
130
+ "type": "object",
131
+ "properties": {
132
+ "api": {
133
+ "oneOf": [
134
+ {
135
+ "type": "string",
136
+ "pattern": "^https://api\\.bilibili\\.com/x/web-interface/popular\\?"
137
+ },
138
+ {
139
+ "type": "null"
140
+ }
141
+ ]
142
+ },
143
+ "page": {
144
+ "type": "string",
145
+ "pattern": "^https://www\\.bilibili\\.com/"
146
+ }
147
+ },
148
+ "required": [
149
+ "api",
150
+ "page"
151
+ ],
152
+ "additionalProperties": false
153
+ }
154
+ },
155
+ "required": [
156
+ "success",
157
+ "status",
158
+ "page",
159
+ "videos",
160
+ "sources"
161
+ ],
162
+ "additionalProperties": false
163
+ },
164
+ {
165
+ "type": "object",
166
+ "properties": {
167
+ "success": {
168
+ "const": true
169
+ },
170
+ "status": {
171
+ "const": "empty"
172
+ },
173
+ "page": {
174
+ "type": "integer",
175
+ "minimum": 1
176
+ },
177
+ "videos": {
178
+ "type": "array",
179
+ "minItems": 0,
180
+ "maxItems": 0
181
+ },
182
+ "sources": {
183
+ "type": "object",
184
+ "properties": {
185
+ "api": {
186
+ "oneOf": [
187
+ {
188
+ "type": "string",
189
+ "pattern": "^https://api\\.bilibili\\.com/x/web-interface/popular\\?"
190
+ },
191
+ {
192
+ "type": "null"
193
+ }
194
+ ]
195
+ },
196
+ "page": {
197
+ "type": "string",
198
+ "pattern": "^https://www\\.bilibili\\.com/"
199
+ }
200
+ },
201
+ "required": [
202
+ "api",
203
+ "page"
204
+ ],
205
+ "additionalProperties": false
206
+ }
207
+ },
208
+ "required": [
209
+ "success",
210
+ "status",
211
+ "page",
212
+ "videos",
213
+ "sources"
214
+ ],
215
+ "additionalProperties": false
216
+ }
217
+ ]
218
+ },
219
+ "steps": [
220
+ {
221
+ "tool": "chrome_javascript",
222
+ "args": {
223
+ "code": "const limit = Math.max(1, Math.min(Number(input.limit) || 10, 20));\nconst page = Math.max(1, Math.min(Math.floor(Number(input.page) || 1), 10));\nconst pageUrl = 'https://www.bilibili.com/v/popular/all';\nconst origin = typeof location !== 'undefined' && typeof location.origin === 'string' && /^https:\\/\\/(?:www\\.|m\\.)?bilibili\\.com$/i.test(location.origin) ? location.origin : '';\nif (!origin) {\n return { success: false, status: 'page_not_ready', page, message: 'Bilibili page origin is not ready', source: pageUrl };\n}\nconst endpoint = new URL('/x/web-interface/popular', 'https://api.bilibili.com');\nendpoint.searchParams.set('ps', String(limit));\nendpoint.searchParams.set('pn', String(page));\nconst mapApiVideos = list => {\n const out = [];\n const seen = new Set();\n for (const item of list) {\n const bvid = String((item && item.bvid) || '').trim();\n const title = String((item && item.title) || '').trim();\n if (!/^BV[0-9A-Za-z]+$/.test(bvid) || !title || seen.has(bvid)) continue;\n seen.add(bvid);\n const stat = (item && item.stat) || {};\n out.push({\n bvid,\n title,\n url: 'https://www.bilibili.com/video/' + bvid,\n author: String((item && item.owner && item.owner.name) || '').trim(),\n category: String((item && item.tname) || '').trim(),\n durationSeconds: Math.max(0, Math.floor(Number(item && item.duration) || 0)),\n views: Math.max(0, Math.floor(Number(stat.view) || 0)),\n likes: Math.max(0, Math.floor(Number(stat.like) || 0)),\n danmaku: Math.max(0, Math.floor(Number(stat.danmaku) || 0)),\n publishedAt: Math.max(0, Math.floor(Number(item && item.pubdate) || 0))\n });\n if (out.length >= limit) break;\n }\n return out;\n};\nconst readFallbackVideos = () => {\n if (page !== 1) return [];\n const root = typeof globalThis !== 'undefined' ? globalThis : {};\n const state = root.__INITIAL_STATE__;\n if (state && typeof state === 'object') {\n const candidates = [state.popularList, state.list, state.rankList, state.videoList];\n for (const list of candidates) {\n if (Array.isArray(list) && list.length > 0) {\n const mapped = mapApiVideos(list);\n if (mapped.length > 0) return mapped;\n }\n }\n }\n if (typeof document === 'undefined' || !document || typeof document.querySelectorAll !== 'function') return [];\n const isHidden = el => Boolean(el && (el.hidden === true || (typeof el.hasAttribute === 'function' && el.hasAttribute('hidden')) || (typeof el.getAttribute === 'function' && el.getAttribute('aria-hidden') === 'true')));\n const out = [];\n const seen = new Set();\n const cards = Array.from(document.querySelectorAll('.video-card, .rank-item, .popular-video-card'));\n const nodes = cards.length > 0 ? cards : Array.from(document.querySelectorAll('a[href*=\"/video/BV\"]'));\n for (const node of nodes) {\n if (isHidden(node)) continue;\n const link = node.matches && node.matches('a[href]') ? node : (typeof node.querySelector === 'function' ? node.querySelector('a[href*=\"/video/BV\"]') : null);\n const href = link && typeof link.getAttribute === 'function' ? String(link.getAttribute('href') || '') : '';\n const m = href.match(/\\/video\\/(BV[0-9A-Za-z]+)/);\n const bvid = m ? m[1] : '';\n if (!bvid || seen.has(bvid)) continue;\n const titleEl = typeof node.querySelector === 'function' ? node.querySelector('.video-name, .title, h3, [title]') : null;\n const title = String((titleEl && ((typeof titleEl.getAttribute === 'function' && titleEl.getAttribute('title')) || titleEl.innerText || titleEl.textContent)) || (link && ((typeof link.getAttribute === 'function' && link.getAttribute('title')) || link.innerText || link.textContent)) || '').trim();\n if (!title) continue;\n const authorEl = typeof node.querySelector === 'function' ? node.querySelector('.up-name__text, .up-name, .author') : null;\n seen.add(bvid);\n out.push({\n bvid,\n title,\n url: 'https://www.bilibili.com/video/' + bvid,\n author: authorEl ? String(authorEl.innerText || authorEl.textContent || '').trim() : '',\n category: '',\n durationSeconds: 0,\n views: 0,\n likes: 0,\n danmaku: 0,\n publishedAt: 0\n });\n if (out.length >= limit) break;\n }\n return out;\n};\nconst tryFallback = () => {\n const videos = readFallbackVideos();\n if (!videos.length) return null;\n return {\n success: true,\n status: 'ok',\n page,\n videos,\n sources: { api: null, page: pageUrl }\n };\n};\nlet response;\ntry {\n response = await fetch(endpoint.href, { credentials: 'include', headers: { Accept: 'application/json' } });\n} catch (error) {\n const fb = tryFallback();\n if (fb) return fb;\n return { success: false, status: 'fetch_error', page, message: String(error && error.message || error), source: endpoint.href };\n}\nif (response.status === 403) {\n const fb = tryFallback();\n if (fb) return fb;\n return { success: false, status: 'requires_auth', page, requiresLogin: true, httpStatus: 403, source: response.url || endpoint.href };\n}\nif (response.status === 412 || response.status === 429) {\n const fb = tryFallback();\n if (fb) return fb;\n return { success: false, status: 'rate_limited', page, httpStatus: response.status, source: response.url || endpoint.href };\n}\nif (!response.ok) {\n const fb = tryFallback();\n if (fb) return fb;\n return { success: false, status: 'http_error', page, httpStatus: response.status, source: response.url || endpoint.href };\n}\nlet payload;\ntry {\n payload = await response.json();\n} catch {\n const fb = tryFallback();\n if (fb) return fb;\n return { success: false, status: 'invalid_json', page, source: response.url || endpoint.href };\n}\nif (!payload || typeof payload !== 'object') {\n const fb = tryFallback();\n if (fb) return fb;\n return { success: false, status: 'schema_changed', page, source: response.url || endpoint.href };\n}\nif (payload.code === -101 || payload.code === -403) {\n const fb = tryFallback();\n if (fb) return fb;\n return { success: false, status: 'requires_auth', page, requiresLogin: true, code: payload.code, message: String(payload.message || 'Bilibili requires authentication'), source: response.url || endpoint.href };\n}\nif (payload.code === -352 || payload.code === -412) {\n const fb = tryFallback();\n if (fb) return fb;\n return { success: false, status: 'rate_limited', page, code: payload.code, message: String(payload.message || 'Bilibili risk control triggered'), source: response.url || endpoint.href };\n}\nif (payload.code !== 0 || !payload.data || !Array.isArray(payload.data.list)) {\n const fb = tryFallback();\n if (fb) return fb;\n return { success: false, status: 'schema_changed', page, code: payload.code, message: String(payload.message || ''), source: response.url || endpoint.href };\n}\nif (payload.data.list.length === 0) {\n return { success: true, status: 'empty', page, videos: [], sources: { api: response.url || endpoint.href, page: pageUrl } };\n}\nconst videos = mapApiVideos(payload.data.list);\nif (!videos.length) {\n return { success: false, status: 'schema_changed', page, source: response.url || endpoint.href };\n}\nreturn {\n success: true,\n status: 'ok',\n page,\n videos,\n sources: { api: response.url || endpoint.href, page: pageUrl }\n};",
224
+ "timeoutMs": 30000
225
+ },
226
+ "resultPath": "/result"
227
+ }
228
+ ],
229
+ "verification": {
230
+ "tool": "chrome_network_request",
231
+ "args": {
232
+ "url": "https://api.bilibili.com/x/web-interface/popular?ps=1&pn=1",
233
+ "method": "GET",
234
+ "timeout": 30000
235
+ },
236
+ "resultPath": "/response/body"
237
+ },
238
+ "tests": [
239
+ {
240
+ "inputs": {
241
+ "limit": 3,
242
+ "page": 1
243
+ },
244
+ "expect": {
245
+ "type": "object",
246
+ "properties": {
247
+ "success": {
248
+ "const": true
249
+ },
250
+ "status": {
251
+ "const": "ok"
252
+ },
253
+ "page": {
254
+ "const": 1
255
+ },
256
+ "videos": {
257
+ "type": "array",
258
+ "minItems": 1
259
+ },
260
+ "sources": {
261
+ "type": "object",
262
+ "required": [
263
+ "api",
264
+ "page"
265
+ ]
266
+ }
267
+ },
268
+ "required": [
269
+ "success",
270
+ "status",
271
+ "page",
272
+ "videos",
273
+ "sources"
274
+ ]
275
+ },
276
+ "observe": {
277
+ "type": "object",
278
+ "properties": {
279
+ "code": {
280
+ "const": 0
281
+ },
282
+ "data": {
283
+ "type": "object",
284
+ "properties": {
285
+ "list": {
286
+ "type": "array",
287
+ "minItems": 1
288
+ }
289
+ },
290
+ "required": [
291
+ "list"
292
+ ]
293
+ }
294
+ },
295
+ "required": [
296
+ "code",
297
+ "data"
298
+ ]
299
+ }
300
+ },
301
+ {
302
+ "inputs": {
303
+ "limit": 5,
304
+ "page": 2
305
+ },
306
+ "expect": {
307
+ "type": "object",
308
+ "properties": {
309
+ "success": {
310
+ "const": true
311
+ },
312
+ "status": {
313
+ "const": "ok"
314
+ },
315
+ "page": {
316
+ "const": 2
317
+ },
318
+ "videos": {
319
+ "type": "array",
320
+ "minItems": 1
321
+ },
322
+ "sources": {
323
+ "type": "object",
324
+ "required": [
325
+ "api",
326
+ "page"
327
+ ]
328
+ }
329
+ },
330
+ "required": [
331
+ "success",
332
+ "status",
333
+ "page",
334
+ "videos",
335
+ "sources"
336
+ ]
337
+ },
338
+ "observe": {
339
+ "type": "object",
340
+ "properties": {
341
+ "code": {
342
+ "const": 0
343
+ },
344
+ "data": {
345
+ "type": "object",
346
+ "properties": {
347
+ "list": {
348
+ "type": "array",
349
+ "minItems": 1
350
+ }
351
+ },
352
+ "required": [
353
+ "list"
354
+ ]
355
+ }
356
+ },
357
+ "required": [
358
+ "code",
359
+ "data"
360
+ ]
361
+ }
362
+ }
363
+ ]
364
+ }