browserpaw 0.0.0-stage → 5.0.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.
Files changed (45) 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 +4028 -0
  5. package/dist/v5/extension/assets/popup-Djl4pI1R.css +359 -0
  6. package/dist/v5/extension/background.js +37712 -0
  7. package/dist/v5/extension/browserpaw-build.json +184 -0
  8. package/dist/v5/extension/chunks/popup-DjxqduQH.js +6542 -0
  9. package/dist/v5/extension/content-scripts/agent-cursor.js +1459 -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 +1883 -0
  17. package/dist/v5/extension/inject-scripts/keyboard-helper.js +402 -0
  18. package/dist/v5/extension/inject-scripts/network-helper.js +213 -0
  19. package/dist/v5/extension/inject-scripts/screenshot-helper.js +408 -0
  20. package/dist/v5/extension/inpage-engine.js +9300 -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 +19441 -0
  24. package/dist/v5/recipes/developer.mozilla.org.md +15 -0
  25. package/dist/v5/recipes/github-releases.json +177 -0
  26. package/dist/v5/recipes/mdn-search.json +174 -0
  27. package/dist/v5/recipes/npm-compare.json +456 -0
  28. package/dist/v5/recipes/x-search-thread.json +321 -0
  29. package/dist/v5/recipes/x-visible-thread.json +303 -0
  30. package/dist/v5/run_host.bat +7 -0
  31. package/dist/v5/run_host.sh +6 -0
  32. package/dist/v5/skill/browserpaw/SKILL.md +48 -0
  33. package/dist/v5/skill/browserpaw/assets/recipes/developer.mozilla.org.md +15 -0
  34. package/dist/v5/skill/browserpaw/assets/recipes/github-releases.json +177 -0
  35. package/dist/v5/skill/browserpaw/assets/recipes/mdn-search.json +174 -0
  36. package/dist/v5/skill/browserpaw/assets/recipes/npm-compare.json +456 -0
  37. package/dist/v5/skill/browserpaw/assets/recipes/x-search-thread.json +321 -0
  38. package/dist/v5/skill/browserpaw/assets/recipes/x-visible-thread.json +303 -0
  39. package/dist/v5/skill/browserpaw/references/TROUBLESHOOTING.md +7 -0
  40. package/dist/v5/skill/browserpaw/references/TROUBLESHOOTING.zh-CN.md +5 -0
  41. package/dist/v5/skill/browserpaw/references/browser-data.md +33 -0
  42. package/dist/v5/skill/browserpaw/references/commands.md +103 -0
  43. package/dist/v5/skill/browserpaw/references/debugging.md +32 -0
  44. package/dist/v5/skill/browserpaw/references/recipe-contract.md +46 -0
  45. package/package.json +67 -4
@@ -0,0 +1,408 @@
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
+ // StyleStack: safely record and restore inline styles, classes, and injected stylesheets
14
+ const StyleStack = {
15
+ _stack: [],
16
+ _fixedStack: [],
17
+ _styleSheets: [],
18
+ _sliceStyleSheets: [],
19
+
20
+ // Record beforeCss and apply inline styles with !important
21
+ add(el, styles) {
22
+ if (!el || !el.style) return;
23
+ const beforeCss = el.style.cssText;
24
+ for (const [prop, val] of Object.entries(styles)) {
25
+ const kebab = prop.replace(/([a-zA-Z])(?=[A-Z])/g, '$1-').toLowerCase();
26
+ try {
27
+ el.style.setProperty(kebab, val, 'important');
28
+ } catch {
29
+ el.style[prop] = val;
30
+ }
31
+ }
32
+ this._stack.push({ el, before: beforeCss });
33
+ },
34
+
35
+ addFixed(el, styles, options = {}) {
36
+ if (!el || !el.style) return;
37
+ const beforeCss = el.style.cssText;
38
+ const hadOriginalId =
39
+ typeof el.hasAttribute === 'function' ? el.hasAttribute('id') : Boolean(el.id);
40
+ const originalId = hadOriginalId ? el.getAttribute('id') : null;
41
+ const addedId = options.addedId || false;
42
+ for (const [prop, val] of Object.entries(styles)) {
43
+ const kebab = prop.replace(/([a-zA-Z])(?=[A-Z])/g, '$1-').toLowerCase();
44
+ try {
45
+ el.style.setProperty(kebab, val, 'important');
46
+ } catch {
47
+ el.style[prop] = val;
48
+ }
49
+ }
50
+ this._fixedStack.push({ el, before: beforeCss, addedId, hadOriginalId, originalId });
51
+ },
52
+
53
+ addStyleSheet(css) {
54
+ const styleEl = document.createElement('style');
55
+ styleEl.type = 'text/css';
56
+ styleEl.appendChild(document.createTextNode(css));
57
+ const parent = document.head || document.documentElement || document.body;
58
+ if (parent) {
59
+ parent.appendChild(styleEl);
60
+ this._styleSheets.push(styleEl);
61
+ }
62
+ },
63
+
64
+ addSliceStyleSheet(css) {
65
+ const styleEl = document.createElement('style');
66
+ styleEl.type = 'text/css';
67
+ styleEl.appendChild(document.createTextNode(css));
68
+ const parent = document.head || document.documentElement || document.body;
69
+ if (parent) {
70
+ parent.appendChild(styleEl);
71
+ this._sliceStyleSheets.push(styleEl);
72
+ }
73
+ },
74
+
75
+ // Pop all fixed slice modifications (restores elements before applying next slice rules)
76
+ popAllFixed() {
77
+ while (this._fixedStack.length > 0) {
78
+ const item = this._fixedStack.pop();
79
+ if (item && item.el) {
80
+ item.el.style.cssText = item.before;
81
+ if (item.addedId) {
82
+ if (item.hadOriginalId && item.originalId !== null) {
83
+ item.el.setAttribute('id', item.originalId);
84
+ } else {
85
+ item.el.removeAttribute('id');
86
+ }
87
+ }
88
+ }
89
+ }
90
+ while (this._sliceStyleSheets.length > 0) {
91
+ const sheet = this._sliceStyleSheets.pop();
92
+ if (sheet && sheet.parentNode) {
93
+ sheet.parentNode.removeChild(sheet);
94
+ }
95
+ }
96
+ },
97
+
98
+ // 100% complete rollback of all DOM style mutations and added stylesheets
99
+ popAll() {
100
+ this.popAllFixed();
101
+ while (this._stack.length > 0) {
102
+ const item = this._stack.pop();
103
+ if (item && item.el) {
104
+ item.el.style.cssText = item.before;
105
+ }
106
+ }
107
+ while (this._styleSheets.length > 0) {
108
+ const sheet = this._styleSheets.pop();
109
+ if (sheet && sheet.parentNode) {
110
+ sheet.parentNode.removeChild(sheet);
111
+ }
112
+ }
113
+ },
114
+ };
115
+
116
+ // Expose on window for debugging / test inspection
117
+ if (typeof window !== 'undefined') {
118
+ window.__mcpStyleStack = StyleStack;
119
+ }
120
+
121
+ let originalOverflowStyle = '';
122
+ let hiddenFixedElements = [];
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') return;
155
+
156
+ if (style.position === 'sticky') {
157
+ stickies.push(el);
158
+ } else if (style.position === 'fixed') {
159
+ const rect = el.getBoundingClientRect();
160
+ // Skip elements completely outside viewport
161
+ if (
162
+ rect.bottom <= 0 ||
163
+ rect.right <= 0 ||
164
+ rect.top >= viewportHeight ||
165
+ rect.left >= viewportWidth
166
+ ) {
167
+ return;
168
+ }
169
+ // Fixed header: docked at top
170
+ if (rect.top <= 45 && rect.height < viewportHeight * 0.5) {
171
+ headers.push(el);
172
+ }
173
+ // Fixed bottom banner / floating footer: docked at bottom
174
+ else if (rect.bottom >= viewportHeight - 45 && rect.height < viewportHeight * 0.5) {
175
+ footers.push(el);
176
+ } else {
177
+ otherFixed.push(el);
178
+ }
179
+ }
180
+ });
181
+
182
+ return { headers, footers, stickies, otherFixed };
183
+ }
184
+
185
+ /**
186
+ * Configure DOM visibility for the current capture slice.
187
+ * - Screen 1 (stepIndex 0): Headers visible, bottom banners hidden (unless also last step).
188
+ * - Screen 2+ (stepIndex > 0): Headers hidden (visibility: hidden) to prevent duplicate banners.
189
+ * - Stickies: converted to relative to prevent repetitive sticking across slices.
190
+ * - Last slice (isLastStep true): Bottom banners visible once at the bottom of the page.
191
+ */
192
+ function prepareSlice(stepIndex, isLastStep) {
193
+ StyleStack.popAllFixed();
194
+
195
+ const { headers, footers, stickies, otherFixed } = categorizeFixedAndStickyElements();
196
+
197
+ if (stepIndex > 0) {
198
+ // Screen 2+: Hide fixed headers to prevent duplication across slices
199
+ headers.forEach((el) => {
200
+ StyleStack.addFixed(el, { visibility: 'hidden', overflow: 'hidden' });
201
+ });
202
+
203
+ // Stickies: convert to relative coordinates and inject stylesheet rule with !important
204
+ stickies.forEach((el, idx) => {
205
+ let addedId = false;
206
+ if (!el.id) {
207
+ el.id = `__mcp_sticky_${Date.now()}_${idx}`;
208
+ addedId = true;
209
+ }
210
+ StyleStack.addFixed(
211
+ el,
212
+ {
213
+ position: 'relative',
214
+ top: 'auto',
215
+ left: 'auto',
216
+ right: 'auto',
217
+ bottom: 'auto',
218
+ },
219
+ { addedId },
220
+ );
221
+ });
222
+ if (stickies.length > 0 && typeof CSS !== 'undefined' && typeof CSS.escape === 'function') {
223
+ const stickySelectors = stickies.map((el) => `#${CSS.escape(el.id)}`).join(', ');
224
+ StyleStack.addSliceStyleSheet(
225
+ `${stickySelectors} { position: relative !important; left: auto !important; right: auto !important; top: auto !important; bottom: auto !important; }`,
226
+ );
227
+ }
228
+
229
+ // Other fixed elements (floating buttons, widgets): hide on subsequent slices
230
+ otherFixed.forEach((el) => {
231
+ StyleStack.addFixed(el, { visibility: 'hidden' });
232
+ });
233
+ }
234
+
235
+ if (!isLastStep) {
236
+ // Prior to the last slice: hide floating bottom banners so they only appear at the bottom
237
+ footers.forEach((el) => {
238
+ StyleStack.addFixed(el, { visibility: 'hidden', overflow: 'hidden' });
239
+ });
240
+ }
241
+ }
242
+
243
+ /**
244
+ * Backward compatibility helpers
245
+ */
246
+ function hideFixedElements() {
247
+ prepareSlice(1, false);
248
+ }
249
+
250
+ function showFixedElements() {
251
+ StyleStack.popAllFixed();
252
+ }
253
+
254
+ /**
255
+ * Measure full page dimensions accurately
256
+ */
257
+ function getDocumentDimensions() {
258
+ const body = document.body;
259
+ const html = document.documentElement;
260
+ const totalWidth = Math.max(
261
+ body ? body.scrollWidth : 0,
262
+ body ? body.offsetWidth : 0,
263
+ html ? html.clientWidth : 0,
264
+ html ? html.scrollWidth : 0,
265
+ html ? html.offsetWidth : 0,
266
+ );
267
+ const totalHeight = Math.max(
268
+ body ? body.scrollHeight : 0,
269
+ body ? body.offsetHeight : 0,
270
+ html ? html.clientHeight : 0,
271
+ html ? html.scrollHeight : 0,
272
+ html ? html.offsetHeight : 0,
273
+ );
274
+ return {
275
+ totalWidth: totalWidth || window.innerWidth,
276
+ totalHeight: totalHeight || window.innerHeight,
277
+ viewportWidth: window.innerWidth,
278
+ viewportHeight: window.innerHeight,
279
+ devicePixelRatio: window.devicePixelRatio || 1,
280
+ currentScrollX: window.scrollX,
281
+ currentScrollY: window.scrollY,
282
+ };
283
+ }
284
+
285
+ // Listen for messages from the extension
286
+ chrome.runtime.onMessage.addListener((request, _sender, sendResponse) => {
287
+ // Respond to ping message
288
+ if (
289
+ request.action === 'chrome_screenshot_ping' ||
290
+ String(request.action || '').startsWith('mcp_ping_')
291
+ ) {
292
+ sendResponse({ status: 'pong' });
293
+ return false; // Synchronous response
294
+ }
295
+
296
+ // Prepare page for capture
297
+ else if (request.action === 'preparePageForCapture') {
298
+ originalOverflowStyle = document.documentElement.style.overflow;
299
+ // GoFullPage industrial scrollbar hiding via non-destructive CSS stylesheet
300
+ // Avoids setting overflow: hidden on html/body which could freeze programmatic window.scrollTo
301
+ StyleStack.addStyleSheet(
302
+ 'html::-webkit-scrollbar, body::-webkit-scrollbar { display: none !important; width: 0 !important; height: 0 !important; }\n' +
303
+ 'html, body { scrollbar-width: none !important; -ms-overflow-style: none !important; }',
304
+ );
305
+ if (request.options?.fullPage) {
306
+ prepareSlice(0, false);
307
+ }
308
+ // Give styles a moment to apply
309
+ setTimeout(() => {
310
+ sendResponse({ success: true });
311
+ }, 50);
312
+ return true; // Async response
313
+ }
314
+
315
+ // Prepare specific slice for full-page capture
316
+ else if (request.action === 'prepareSlice') {
317
+ prepareSlice(request.stepIndex || 0, Boolean(request.isLastStep));
318
+ setTimeout(() => {
319
+ sendResponse({ success: true });
320
+ }, 30);
321
+ return true; // Async response
322
+ }
323
+
324
+ // Pop slice-specific fixed styles between slices
325
+ else if (request.action === 'popSliceFixed') {
326
+ StyleStack.popAllFixed();
327
+ sendResponse({ success: true });
328
+ return false;
329
+ }
330
+
331
+ // Page warmup: rapid scroll down and back up to trigger IntersectionObserver, lazy loading, and skeletons
332
+ else if (request.action === 'warmupPage') {
333
+ const dims = getDocumentDimensions();
334
+ const maxScrollY = Math.max(0, dims.totalHeight - window.innerHeight);
335
+
336
+ if (maxScrollY > 0) {
337
+ window.scrollTo({ left: 0, top: maxScrollY, behavior: 'instant' });
338
+ }
339
+
340
+ setTimeout(() => {
341
+ // GoFullPage standard: scroll cleanly back to (0, 0) ready for slice 0
342
+ window.scrollTo({ left: 0, top: 0, behavior: 'instant' });
343
+ setTimeout(() => {
344
+ const settledDims = getDocumentDimensions();
345
+ sendResponse({
346
+ success: true,
347
+ totalWidth: settledDims.totalWidth,
348
+ totalHeight: settledDims.totalHeight,
349
+ });
350
+ }, 80);
351
+ }, 80);
352
+ return true; // Async response
353
+ }
354
+
355
+ // Get page details
356
+ else if (request.action === 'getPageDetails') {
357
+ sendResponse(getDocumentDimensions());
358
+ return false;
359
+ }
360
+
361
+ // Get element details
362
+ else if (request.action === 'getElementDetails') {
363
+ const element = document.querySelector(request.selector);
364
+ if (element) {
365
+ element.scrollIntoView({ behavior: 'instant', block: 'nearest', inline: 'nearest' });
366
+ setTimeout(() => {
367
+ const rect = element.getBoundingClientRect();
368
+ sendResponse({
369
+ rect: { x: rect.left, y: rect.top, width: rect.width, height: rect.height },
370
+ devicePixelRatio: window.devicePixelRatio || 1,
371
+ });
372
+ }, 200);
373
+ return true;
374
+ } else {
375
+ sendResponse({ error: `Element with selector "${request.selector}" not found.` });
376
+ return false;
377
+ }
378
+ }
379
+
380
+ // Scroll page with dynamic height change detection
381
+ else if (request.action === 'scrollPage') {
382
+ window.scrollTo({ left: request.x, top: request.y, behavior: 'instant' });
383
+ setTimeout(() => {
384
+ const dims = getDocumentDimensions();
385
+ sendResponse({
386
+ success: true,
387
+ newScrollX: window.scrollX,
388
+ newScrollY: window.scrollY,
389
+ totalHeight: dims.totalHeight,
390
+ totalWidth: dims.totalWidth,
391
+ });
392
+ }, request.scrollDelay || 300);
393
+ return true;
394
+ }
395
+
396
+ // Reset page after capture: 100% restore original styles and DOM via StyleStack.popAll()
397
+ else if (request.action === 'resetPageAfterCapture') {
398
+ document.documentElement.style.overflow = originalOverflowStyle;
399
+ StyleStack.popAll();
400
+ if (typeof request.scrollX !== 'undefined' && typeof request.scrollY !== 'undefined') {
401
+ window.scrollTo({ left: request.scrollX, top: request.scrollY, behavior: 'instant' });
402
+ }
403
+ sendResponse({ success: true });
404
+ return false;
405
+ }
406
+
407
+ return false;
408
+ });