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,449 @@
1
+ /**
2
+ * Screenshot helper content script
3
+ * Handles page preparation, scrolling, element positioning, and GoFullPage-grade
4
+ * StyleStack fixed/sticky element management, warmup, and dynamic height tracking.
5
+ */
6
+
7
+ // NOTE: no init-guard here. The isolated world persists across extension
8
+ // reloads while the old listener's runtime binding dies with the old context;
9
+ // skipping re-registration leaves only a dead listener that never answers
10
+ // chrome.tabs.sendMessage, hanging the tool forever. Always register fresh -
11
+ // the alive listener resolves the message channel.
12
+
13
+ (() => {
14
+ // StyleStack: safely record and restore inline styles, classes, and injected stylesheets
15
+ const StyleStack = {
16
+ _stack: [],
17
+ _fixedStack: [],
18
+ _styleSheets: [],
19
+ _sliceStyleSheets: [],
20
+
21
+ // Record beforeCss and apply inline styles with !important
22
+ add(el, styles) {
23
+ if (!el || !el.style) return;
24
+ const beforeCss = el.style.cssText;
25
+ for (const [prop, val] of Object.entries(styles)) {
26
+ const kebab = prop.replace(/([a-zA-Z])(?=[A-Z])/g, '$1-').toLowerCase();
27
+ try {
28
+ el.style.setProperty(kebab, val, 'important');
29
+ } catch {
30
+ el.style[prop] = val;
31
+ }
32
+ }
33
+ this._stack.push({ el, before: beforeCss });
34
+ },
35
+
36
+ addFixed(el, styles, options = {}) {
37
+ if (!el || !el.style) return;
38
+ const beforeCss = el.style.cssText;
39
+ const hadOriginalId =
40
+ typeof el.hasAttribute === 'function' ? el.hasAttribute('id') : Boolean(el.id);
41
+ const originalId = hadOriginalId ? el.getAttribute('id') : null;
42
+ const addedId = options.addedId || false;
43
+ for (const [prop, val] of Object.entries(styles)) {
44
+ const kebab = prop.replace(/([a-zA-Z])(?=[A-Z])/g, '$1-').toLowerCase();
45
+ try {
46
+ el.style.setProperty(kebab, val, 'important');
47
+ } catch {
48
+ el.style[prop] = val;
49
+ }
50
+ }
51
+ this._fixedStack.push({ el, before: beforeCss, addedId, hadOriginalId, originalId });
52
+ },
53
+
54
+ addStyleSheet(css) {
55
+ const styleEl = document.createElement('style');
56
+ styleEl.type = 'text/css';
57
+ styleEl.appendChild(document.createTextNode(css));
58
+ const parent = document.head || document.documentElement || document.body;
59
+ if (parent) {
60
+ parent.appendChild(styleEl);
61
+ this._styleSheets.push(styleEl);
62
+ }
63
+ },
64
+
65
+ addSliceStyleSheet(css) {
66
+ const styleEl = document.createElement('style');
67
+ styleEl.type = 'text/css';
68
+ styleEl.appendChild(document.createTextNode(css));
69
+ const parent = document.head || document.documentElement || document.body;
70
+ if (parent) {
71
+ parent.appendChild(styleEl);
72
+ this._sliceStyleSheets.push(styleEl);
73
+ }
74
+ },
75
+
76
+ // Pop all fixed slice modifications (restores elements before applying next slice rules)
77
+ popAllFixed() {
78
+ while (this._fixedStack.length > 0) {
79
+ const item = this._fixedStack.pop();
80
+ if (item && item.el) {
81
+ item.el.style.cssText = item.before;
82
+ if (item.addedId) {
83
+ if (item.hadOriginalId && item.originalId !== null) {
84
+ item.el.setAttribute('id', item.originalId);
85
+ } else {
86
+ item.el.removeAttribute('id');
87
+ }
88
+ }
89
+ }
90
+ }
91
+ while (this._sliceStyleSheets.length > 0) {
92
+ const sheet = this._sliceStyleSheets.pop();
93
+ if (sheet && sheet.parentNode) {
94
+ sheet.parentNode.removeChild(sheet);
95
+ }
96
+ }
97
+ },
98
+
99
+ // 100% complete rollback of all DOM style mutations and added stylesheets
100
+ popAll() {
101
+ this.popAllFixed();
102
+ while (this._stack.length > 0) {
103
+ const item = this._stack.pop();
104
+ if (item && item.el) {
105
+ item.el.style.cssText = item.before;
106
+ }
107
+ }
108
+ while (this._styleSheets.length > 0) {
109
+ const sheet = this._styleSheets.pop();
110
+ if (sheet && sheet.parentNode) {
111
+ sheet.parentNode.removeChild(sheet);
112
+ }
113
+ }
114
+ },
115
+ };
116
+
117
+ // Expose on window for debugging / test inspection
118
+ if (typeof window !== 'undefined') {
119
+ window.__mcpStyleStack = StyleStack;
120
+ }
121
+
122
+ let originalOverflowStyle = '';
123
+
124
+ // querySelectorAll('*') does not cross shadow boundaries; walk open shadow roots
125
+ // (nested included) so shadow-DOM fixed/sticky elements are captured too.
126
+ function collectElementsIncludingShadowRoots(root, out = []) {
127
+ for (const el of root.querySelectorAll('*')) {
128
+ out.push(el);
129
+ if (el.shadowRoot) collectElementsIncludingShadowRoots(el.shadowRoot, out);
130
+ }
131
+ return out;
132
+ }
133
+
134
+ /**
135
+ * Categorize fixed, sticky, header, and floating footer elements
136
+ */
137
+ function categorizeFixedAndStickyElements() {
138
+ const headers = [];
139
+ const footers = [];
140
+ const stickies = [];
141
+ const otherFixed = [];
142
+
143
+ const viewportHeight = window.innerHeight;
144
+ const viewportWidth = window.innerWidth;
145
+
146
+ collectElementsIncludingShadowRoots(document).forEach((el) => {
147
+ const tag = el.tagName;
148
+ if (tag === 'SCRIPT' || tag === 'STYLE' || tag === 'NOSCRIPT' || tag === 'LINK') return;
149
+ if (el.id && (el.id.startsWith('chrome-mcp-') || el.id.startsWith('__mcp_'))) return;
150
+
151
+ if (el.offsetWidth <= 1 && el.offsetHeight <= 1) return;
152
+
153
+ const style = window.getComputedStyle(el);
154
+ if (style.display === 'none' || style.visibility === 'hidden' || style.opacity === '0')
155
+ return;
156
+
157
+ if (style.position === 'sticky') {
158
+ stickies.push(el);
159
+ } else if (style.position === 'fixed') {
160
+ const rect = el.getBoundingClientRect();
161
+ // Skip elements completely outside viewport
162
+ if (
163
+ rect.bottom <= 0 ||
164
+ rect.right <= 0 ||
165
+ rect.top >= viewportHeight ||
166
+ rect.left >= viewportWidth
167
+ ) {
168
+ return;
169
+ }
170
+ // Fixed header: docked at top
171
+ if (rect.top <= 45 && rect.height < viewportHeight * 0.5) {
172
+ headers.push(el);
173
+ }
174
+ // Fixed bottom banner / floating footer: docked at bottom
175
+ else if (rect.bottom >= viewportHeight - 45 && rect.height < viewportHeight * 0.5) {
176
+ footers.push(el);
177
+ } else {
178
+ otherFixed.push(el);
179
+ }
180
+ }
181
+ });
182
+
183
+ return { headers, footers, stickies, otherFixed };
184
+ }
185
+
186
+ /**
187
+ * Configure DOM visibility for the current capture slice.
188
+ * - Screen 1 (stepIndex 0): Headers visible, bottom banners hidden (unless also last step).
189
+ * - Screen 2+ (stepIndex > 0): Headers hidden (visibility: hidden) to prevent duplicate banners.
190
+ * - Stickies: converted to relative to prevent repetitive sticking across slices.
191
+ * - Last slice (isLastStep true): Bottom banners visible once at the bottom of the page.
192
+ */
193
+ function prepareSlice(stepIndex, isLastStep) {
194
+ StyleStack.popAllFixed();
195
+
196
+ const { headers, footers, stickies, otherFixed } = categorizeFixedAndStickyElements();
197
+
198
+ if (stepIndex > 0) {
199
+ // Screen 2+: Hide fixed headers to prevent duplication across slices
200
+ headers.forEach((el) => {
201
+ StyleStack.addFixed(el, { visibility: 'hidden', overflow: 'hidden' });
202
+ });
203
+
204
+ // Stickies: convert to relative coordinates and inject stylesheet rule with !important
205
+ stickies.forEach((el, idx) => {
206
+ let addedId = false;
207
+ if (!el.id) {
208
+ el.id = `__mcp_sticky_${Date.now()}_${idx}`;
209
+ addedId = true;
210
+ }
211
+ StyleStack.addFixed(
212
+ el,
213
+ {
214
+ position: 'relative',
215
+ top: 'auto',
216
+ left: 'auto',
217
+ right: 'auto',
218
+ bottom: 'auto',
219
+ },
220
+ { addedId },
221
+ );
222
+ });
223
+ if (stickies.length > 0 && typeof CSS !== 'undefined' && typeof CSS.escape === 'function') {
224
+ const stickySelectors = stickies.map((el) => `#${CSS.escape(el.id)}`).join(', ');
225
+ StyleStack.addSliceStyleSheet(
226
+ `${stickySelectors} { position: relative !important; left: auto !important; right: auto !important; top: auto !important; bottom: auto !important; }`,
227
+ );
228
+ }
229
+
230
+ // Other fixed elements (floating buttons, widgets): hide on subsequent slices
231
+ otherFixed.forEach((el) => {
232
+ StyleStack.addFixed(el, { visibility: 'hidden' });
233
+ });
234
+ }
235
+
236
+ if (!isLastStep) {
237
+ // Prior to the last slice: hide floating bottom banners so they only appear at the bottom
238
+ footers.forEach((el) => {
239
+ StyleStack.addFixed(el, { visibility: 'hidden', overflow: 'hidden' });
240
+ });
241
+ }
242
+ }
243
+
244
+ /**
245
+ * Measure full page dimensions accurately
246
+ */
247
+ function getDocumentDimensions() {
248
+ const body = document.body;
249
+ const html = document.documentElement;
250
+ const totalWidth = Math.max(
251
+ body ? body.scrollWidth : 0,
252
+ body ? body.offsetWidth : 0,
253
+ html ? html.clientWidth : 0,
254
+ html ? html.scrollWidth : 0,
255
+ html ? html.offsetWidth : 0,
256
+ );
257
+ const totalHeight = Math.max(
258
+ body ? body.scrollHeight : 0,
259
+ body ? body.offsetHeight : 0,
260
+ html ? html.clientHeight : 0,
261
+ html ? html.scrollHeight : 0,
262
+ html ? html.offsetHeight : 0,
263
+ );
264
+ return {
265
+ totalWidth: totalWidth || window.innerWidth,
266
+ totalHeight: totalHeight || window.innerHeight,
267
+ viewportWidth: window.innerWidth,
268
+ viewportHeight: window.innerHeight,
269
+ devicePixelRatio: window.devicePixelRatio || 1,
270
+ currentScrollX: window.scrollX,
271
+ currentScrollY: window.scrollY,
272
+ };
273
+ }
274
+
275
+ const formatError = (error) => (error instanceof Error ? error.message : String(error));
276
+
277
+ const safeRespond = (sendResponse, payload) => {
278
+ try {
279
+ sendResponse(payload);
280
+ } catch {}
281
+ };
282
+
283
+ const LISTENER_KEY = '__MCP_SCREENSHOT_HELPER_LISTENER__';
284
+ const priorListener = globalThis[LISTENER_KEY];
285
+ if (typeof priorListener === 'function') {
286
+ try {
287
+ chrome.runtime.onMessage.removeListener(priorListener);
288
+ } catch {}
289
+ }
290
+
291
+ // Listen for messages from the extension
292
+ const onScreenshotMessage = (request, _sender, sendResponse) => {
293
+ if (!request || typeof request !== 'object') return false;
294
+
295
+ try {
296
+ // Respond to ping message
297
+ if (
298
+ request.action === 'chrome_screenshot_ping' ||
299
+ String(request.action || '').startsWith('mcp_ping_')
300
+ ) {
301
+ sendResponse({ status: 'pong' });
302
+ return false; // Synchronous response
303
+ }
304
+
305
+ // Prepare page for capture
306
+ else if (request.action === 'preparePageForCapture') {
307
+ originalOverflowStyle = document.documentElement.style.overflow;
308
+ // GoFullPage industrial scrollbar hiding via non-destructive CSS stylesheet
309
+ // Avoids setting overflow: hidden on html/body which could freeze programmatic window.scrollTo
310
+ StyleStack.addStyleSheet(
311
+ 'html::-webkit-scrollbar, body::-webkit-scrollbar { display: none !important; width: 0 !important; height: 0 !important; }\n' +
312
+ 'html, body { scrollbar-width: none !important; -ms-overflow-style: none !important; }',
313
+ );
314
+ if (request.options?.fullPage) {
315
+ prepareSlice(0, false);
316
+ }
317
+ // Give styles a moment to apply
318
+ setTimeout(() => {
319
+ try {
320
+ sendResponse({ success: true });
321
+ } catch (error) {
322
+ safeRespond(sendResponse, { success: false, error: formatError(error) });
323
+ }
324
+ }, 50);
325
+ return true; // Async response
326
+ }
327
+
328
+ // Prepare specific slice for full-page capture
329
+ else if (request.action === 'prepareSlice') {
330
+ prepareSlice(request.stepIndex || 0, Boolean(request.isLastStep));
331
+ setTimeout(() => {
332
+ try {
333
+ sendResponse({ success: true });
334
+ } catch (error) {
335
+ safeRespond(sendResponse, { success: false, error: formatError(error) });
336
+ }
337
+ }, 30);
338
+ return true; // Async response
339
+ }
340
+
341
+ // Pop slice-specific fixed styles between slices
342
+ else if (request.action === 'popSliceFixed') {
343
+ StyleStack.popAllFixed();
344
+ sendResponse({ success: true });
345
+ return false;
346
+ }
347
+
348
+ // Page warmup: rapid scroll down and back up to trigger IntersectionObserver, lazy loading, and skeletons
349
+ else if (request.action === 'warmupPage') {
350
+ const dims = getDocumentDimensions();
351
+ const maxScrollY = Math.max(0, dims.totalHeight - window.innerHeight);
352
+
353
+ if (maxScrollY > 0) {
354
+ window.scrollTo({ left: 0, top: maxScrollY, behavior: 'instant' });
355
+ }
356
+
357
+ setTimeout(() => {
358
+ try {
359
+ // GoFullPage standard: scroll cleanly back to (0, 0) ready for slice 0
360
+ window.scrollTo({ left: 0, top: 0, behavior: 'instant' });
361
+ setTimeout(() => {
362
+ try {
363
+ const settledDims = getDocumentDimensions();
364
+ sendResponse({
365
+ success: true,
366
+ totalWidth: settledDims.totalWidth,
367
+ totalHeight: settledDims.totalHeight,
368
+ });
369
+ } catch (error) {
370
+ safeRespond(sendResponse, { success: false, error: formatError(error) });
371
+ }
372
+ }, 80);
373
+ } catch (error) {
374
+ safeRespond(sendResponse, { success: false, error: formatError(error) });
375
+ }
376
+ }, 80);
377
+ return true; // Async response
378
+ }
379
+
380
+ // Get page details
381
+ else if (request.action === 'getPageDetails') {
382
+ sendResponse(getDocumentDimensions());
383
+ return false;
384
+ }
385
+
386
+ // Get element details
387
+ else if (request.action === 'getElementDetails') {
388
+ const element = document.querySelector(request.selector);
389
+ if (element) {
390
+ element.scrollIntoView({ behavior: 'instant', block: 'nearest', inline: 'nearest' });
391
+ setTimeout(() => {
392
+ try {
393
+ const rect = element.getBoundingClientRect();
394
+ sendResponse({
395
+ rect: { x: rect.left, y: rect.top, width: rect.width, height: rect.height },
396
+ devicePixelRatio: window.devicePixelRatio || 1,
397
+ });
398
+ } catch (error) {
399
+ safeRespond(sendResponse, { success: false, error: formatError(error) });
400
+ }
401
+ }, 200);
402
+ return true;
403
+ } else {
404
+ sendResponse({ error: `Element with selector "${request.selector}" not found.` });
405
+ return false;
406
+ }
407
+ }
408
+
409
+ // Scroll page with dynamic height change detection
410
+ else if (request.action === 'scrollPage') {
411
+ window.scrollTo({ left: request.x, top: request.y, behavior: 'instant' });
412
+ setTimeout(() => {
413
+ try {
414
+ const dims = getDocumentDimensions();
415
+ sendResponse({
416
+ success: true,
417
+ newScrollX: window.scrollX,
418
+ newScrollY: window.scrollY,
419
+ totalHeight: dims.totalHeight,
420
+ totalWidth: dims.totalWidth,
421
+ });
422
+ } catch (error) {
423
+ safeRespond(sendResponse, { success: false, error: formatError(error) });
424
+ }
425
+ }, request.scrollDelay || 300);
426
+ return true;
427
+ }
428
+
429
+ // Reset page after capture: 100% restore original styles and DOM via StyleStack.popAll()
430
+ else if (request.action === 'resetPageAfterCapture') {
431
+ document.documentElement.style.overflow = originalOverflowStyle;
432
+ StyleStack.popAll();
433
+ if (typeof request.scrollX !== 'undefined' && typeof request.scrollY !== 'undefined') {
434
+ window.scrollTo({ left: request.scrollX, top: request.scrollY, behavior: 'instant' });
435
+ }
436
+ sendResponse({ success: true });
437
+ return false;
438
+ }
439
+
440
+ return false;
441
+ } catch (error) {
442
+ safeRespond(sendResponse, { success: false, error: formatError(error) });
443
+ return false;
444
+ }
445
+ };
446
+
447
+ globalThis[LISTENER_KEY] = onScreenshotMessage;
448
+ chrome.runtime.onMessage.addListener(onScreenshotMessage);
449
+ })();