@ytspar/sweetlink 1.15.0 → 1.16.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.
@@ -0,0 +1,385 @@
1
+ # Sweetlink CDP (Chrome DevTools Protocol) Guide
2
+
3
+ ## Overview
4
+
5
+ Chrome DevTools Protocol (CDP) provides enhanced screenshot quality and additional debugging capabilities compared to the WebSocket/html2canvas method.
6
+
7
+ ## Advantages of CDP
8
+
9
+ | Feature | WebSocket (html2canvas) | CDP (Puppeteer) |
10
+ |---------|------------------------|-----------------|
11
+ | Screenshot Quality | Good | Excellent |
12
+ | Full Page Screenshots | Limited | Native support |
13
+ | Large Pages | May timeout | Reliable |
14
+ | Network Inspection | ❌ Not available | ✅ Full support |
15
+ | Performance Metrics | ❌ Not available | ✅ Available |
16
+ | Selector Screenshots | Works | More reliable |
17
+ | Setup Required | None | Chrome with remote debugging |
18
+
19
+ ## Starting Chrome with CDP
20
+
21
+ ### macOS
22
+
23
+ ```bash
24
+ /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \
25
+ --remote-debugging-port=9222 \
26
+ --user-data-dir=/tmp/chrome-debug
27
+ ```
28
+
29
+ ### Linux
30
+
31
+ ```bash
32
+ google-chrome \
33
+ --remote-debugging-port=9222 \
34
+ --user-data-dir=/tmp/chrome-debug
35
+ ```
36
+
37
+ ### Windows
38
+
39
+ ```cmd
40
+ "C:\Program Files\Google\Chrome\Application\chrome.exe" ^
41
+ --remote-debugging-port=9222 ^
42
+ --user-data-dir=%TEMP%\chrome-debug
43
+ ```
44
+
45
+ ## Automatic CDP Detection
46
+
47
+ Sweetlink automatically detects if CDP is available and uses it when possible:
48
+
49
+ ```bash
50
+ # This will use CDP if Chrome is running with remote debugging
51
+ pnpm sweetlink screenshot --no-wait --output page.png
52
+
53
+ # Output:
54
+ # [Sweetlink] Using CDP for screenshot
55
+ # [Sweetlink] ✓ Screenshot saved to: page.png
56
+ # [Sweetlink] Method: Chrome DevTools Protocol
57
+ ```
58
+
59
+ ## CDP-Specific Commands
60
+
61
+ ### Network Inspection (CDP Only)
62
+
63
+ ```bash
64
+ # Get all network requests
65
+ pnpm sweetlink network
66
+
67
+ # Filter by URL
68
+ pnpm sweetlink network --filter "/api/"
69
+ pnpm sweetlink network --filter "graphql"
70
+
71
+ # Example output:
72
+ # [Sweetlink] ✓ Found 15 network requests
73
+ #
74
+ # Network Requests:
75
+ #
76
+ # 1. GET http://localhost:3000/api/companies
77
+ # Status: 200 OK
78
+ # Type: xhr
79
+ #
80
+ # 2. GET http://localhost:3000/api/countries
81
+ # Status: 200 OK
82
+ # Type: fetch
83
+ ```
84
+
85
+ ### Enhanced Screenshots
86
+
87
+ ```bash
88
+ # Full page screenshot (works better with CDP)
89
+ pnpm sweetlink screenshot --no-wait --full-page --output fullpage.png
90
+
91
+ # Element screenshot (more reliable with CDP)
92
+ pnpm sweetlink screenshot --no-wait --selector ".company-card" --output card.png
93
+
94
+ # CDP provides better handling of:
95
+ # - Large pages that timeout with html2canvas
96
+ # - Complex CSS and animations
97
+ # - Responsive layouts
98
+ # - High-resolution displays
99
+ ```
100
+
101
+ ## Environment Variables
102
+
103
+ ```bash
104
+ # WebSocket URL (default: ws://localhost:9223)
105
+ export SWEETLINK_WS_URL=ws://localhost:9223
106
+
107
+ # CDP URL (default: http://127.0.0.1:9222)
108
+ export CHROME_CDP_URL=http://127.0.0.1:9222
109
+
110
+ # CDP port (default: 9222)
111
+ export CHROME_CDP_PORT=9222
112
+ ```
113
+
114
+ ## Troubleshooting
115
+
116
+ ### CDP Not Detected
117
+
118
+ **Symptom**: Screenshot command says "Using WebSocket for screenshot"
119
+
120
+ **Solutions**:
121
+
122
+ 1. Check if Chrome is running with remote debugging:
123
+
124
+ ```bash
125
+ curl http://127.0.0.1:9222/json/version
126
+ ```
127
+
128
+ 2. You should see JSON response with browser info:
129
+
130
+ ```json
131
+ {
132
+ "Browser": "Chrome/131.0.6778.205",
133
+ "Protocol-Version": "1.3",
134
+ "User-Agent": "Mozilla/5.0...",
135
+ "WebKit-Version": "537.36"
136
+ }
137
+ ```
138
+
139
+ 3. If not, start Chrome with `--remote-debugging-port=9222` flag
140
+
141
+ ### Connection Refused
142
+
143
+ **Symptom**: `CDP connection failed: connect ECONNREFUSED 127.0.0.1:9222`
144
+
145
+ **Solutions**:
146
+
147
+ 1. Chrome is not running with remote debugging enabled
148
+ 2. Check if another process is using port 9222:
149
+
150
+ ```bash
151
+ lsof -ti:9222
152
+ ```
153
+
154
+ 3. Try a different port:
155
+
156
+ ```bash
157
+ # Start Chrome on port 9223
158
+ --remote-debugging-port=9223
159
+
160
+ # Tell Sweetlink to use that port
161
+ export CHROME_CDP_PORT=9223
162
+ ```
163
+
164
+ ### No Local Development Page Found
165
+
166
+ **Symptom**: `No local development page found`
167
+
168
+ **Solution**:
169
+
170
+ 1. Make sure you have http://localhost:3000 open in the Chrome instance with remote debugging
171
+ 2. Navigate to your dev server before running sweetlink commands
172
+
173
+ ### Screenshot Fails on Large Pages
174
+
175
+ **With WebSocket**: May timeout after 30 seconds
176
+
177
+ **With CDP**: Should work reliably, but may take longer:
178
+
179
+ ```bash
180
+ # If screenshot is slow, try targeting a specific element
181
+ pnpm sweetlink screenshot --no-wait --selector ".main-content"
182
+ ```
183
+
184
+ ## CDP Features Roadmap
185
+
186
+ ### Phase 2 (Current)
187
+
188
+ ✅ Auto-detection
189
+ ✅ Enhanced screenshots
190
+ ✅ Network request inspection
191
+
192
+ ### Phase 3 (Future)
193
+
194
+ - Performance metrics and profiling
195
+ - Console log capture via CDP (in addition to WebSocket)
196
+ - Coverage reports
197
+ - Lighthouse audits
198
+ - Video recording
199
+ - Screenshot diffing
200
+
201
+ ## Comparison: When to Use What
202
+
203
+ ### Use CDP (Recommended) When
204
+
205
+ - Taking screenshots of large or complex pages
206
+ - Need full-page screenshots
207
+ - Investigating network requests
208
+ - Need production-quality screenshots
209
+ - Working on performance optimization
210
+ - Debugging network issues
211
+
212
+ ### Use WebSocket When
213
+
214
+ - CDP not available or not set up
215
+ - Simple element screenshots
216
+ - Quick debugging tasks
217
+ - Don't want to set up Chrome with remote debugging
218
+
219
+ ## Best Practices
220
+
221
+ 1. **Development Workflow**: Start Chrome with CDP at the beginning of your dev session
222
+
223
+ ```bash
224
+ # Add to your shell profile (.zshrc, .bashrc)
225
+ alias chrome-dev='/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222 --user-data-dir=/tmp/chrome-debug'
226
+ ```
227
+
228
+ 2. **CI/CD**: WebSocket method is better for CI environments (no extra Chrome setup needed)
229
+
230
+ 3. **Screenshot Quality**: Always use CDP for screenshots that will be reviewed or shared
231
+
232
+ 4. **Network Debugging**: CDP is the only option for network inspection
233
+
234
+ ## Integration with Claude Agents
235
+
236
+ Claude agents can automatically take advantage of CDP when available:
237
+
238
+ ```bash
239
+ # Agent workflow example:
240
+ # 1. Check if screenshot works
241
+ pnpm sweetlink screenshot --no-wait --output before.png
242
+
243
+ # 2. Make code changes
244
+ # ...
245
+
246
+ # 3. Verify changes
247
+ pnpm sweetlink screenshot --no-wait --output after.png
248
+
249
+ # 4. Check for console errors
250
+ pnpm sweetlink logs --filter error
251
+
252
+ # 5. Verify API calls
253
+ pnpm sweetlink network --filter "/api/"
254
+ ```
255
+
256
+ If CDP is available, the agent gets higher quality screenshots automatically. If not, it falls back to WebSocket gracefully.
257
+
258
+ ## Security Considerations
259
+
260
+ - CDP gives full access to browser debugging features
261
+ - Only use on localhost development
262
+ - Never expose CDP port (9222) to external networks
263
+ - Use temporary user data directory (`--user-data-dir=/tmp`)
264
+ - CDP should NEVER be enabled in production
265
+
266
+ ## Example: Complete Development Session
267
+
268
+ ```bash
269
+ # 1. Start Chrome with CDP
270
+ /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \
271
+ --remote-debugging-port=9222 \
272
+ --user-data-dir=/tmp/chrome-debug \
273
+ http://localhost:3000 &
274
+
275
+ # 2. Start dev server (in another terminal)
276
+ pnpm run dev
277
+
278
+ # 3. Take baseline screenshot
279
+ pnpm sweetlink screenshot --no-wait --output baseline.png
280
+
281
+ # 4. Make code changes
282
+ # ... edit files ...
283
+
284
+ # 5. Verify changes
285
+ pnpm sweetlink screenshot --no-wait --output modified.png
286
+
287
+ # 6. Check console for errors
288
+ pnpm sweetlink logs --filter error
289
+
290
+ # 7. Inspect network requests
291
+ pnpm sweetlink network --filter "/api/"
292
+
293
+ # 8. Query DOM to verify changes
294
+ pnpm sweetlink query --selector ".new-feature"
295
+ ```
296
+
297
+ ## Visual Comparison with Overlays
298
+
299
+ When verifying UI changes like card sizes or alignment, use ImageMagick to create annotated overlays on screenshots. This provides precise pixel measurements and visual proof.
300
+
301
+ ### Comparing Element Sizes
302
+
303
+ ```bash
304
+ # 1. Take screenshot
305
+ pnpm sweetlink screenshot --no-wait --url "http://localhost:3000/company/cyera" \
306
+ --output .tmp/screenshots/layout-check.png
307
+
308
+ # 2. Add overlay rectangles and labels using ImageMagick
309
+ convert .tmp/screenshots/layout-check.png \
310
+ -fill 'rgba(255,0,0,0.3)' -stroke 'red' -strokewidth 2 \
311
+ -draw "rectangle 700,655 1295,800" \
312
+ -fill 'rgba(0,255,0,0.3)' -stroke 'lime' -strokewidth 2 \
313
+ -draw "rectangle 700,830 1295,920" \
314
+ -font Helvetica-Bold -pointsize 20 \
315
+ -fill white -stroke black -strokewidth 1 \
316
+ -annotate +710+680 "CARD A: 595px wide" \
317
+ -annotate +710+860 "CARD B: 595px wide" \
318
+ .tmp/screenshots/layout-overlay.png
319
+
320
+ # 3. View the overlay to confirm measurements match
321
+ ```
322
+
323
+ ### Use Cases
324
+
325
+ - **Card width verification**: Confirm two cards have the same width
326
+ - **Alignment debugging**: Check if elements are properly aligned
327
+ - **Spacing validation**: Measure gaps between components
328
+ - **Before/after comparison**: Show exact pixel changes
329
+
330
+ ### ImageMagick Draw Commands
331
+
332
+ ```bash
333
+ # Rectangle overlay (x1,y1 to x2,y2)
334
+ -draw "rectangle 100,200 400,500"
335
+
336
+ # Line
337
+ -draw "line 100,100 500,100"
338
+
339
+ # Circle
340
+ -draw "circle 250,250 300,250"
341
+
342
+ # Text annotation at position (+x+y)
343
+ -annotate +100+200 "Label text"
344
+
345
+ # Colors with transparency
346
+ -fill 'rgba(255,0,0,0.3)' # Red, 30% opacity
347
+ -fill 'rgba(0,255,0,0.3)' # Green, 30% opacity
348
+ -stroke 'red' # Solid red border
349
+ ```
350
+
351
+ ### Agent Workflow Example
352
+
353
+ ```bash
354
+ # Step 1: Screenshot before change
355
+ pnpm sweetlink screenshot --no-wait --output .tmp/screenshots/before.png
356
+
357
+ # Step 2: Make code changes
358
+ # ... edit files ...
359
+
360
+ # Step 3: Screenshot after change
361
+ pnpm sweetlink screenshot --no-wait --output .tmp/screenshots/after.png
362
+
363
+ # Step 4: Create comparison overlay
364
+ convert .tmp/screenshots/after.png \
365
+ -fill 'rgba(0,255,0,0.3)' -stroke 'lime' -strokewidth 2 \
366
+ -draw "rectangle X1,Y1 X2,Y2" \
367
+ -annotate +X1+Y1 "Element: NNNpx wide" \
368
+ .tmp/screenshots/verified.png
369
+
370
+ # Step 5: Read and analyze the overlay image to confirm fix
371
+ ```
372
+
373
+ This technique is especially useful when visual inspection alone is insufficient to verify that elements match exactly.
374
+
375
+ ## Summary
376
+
377
+ CDP provides professional-grade debugging and screenshot capabilities for Sweetlink. While the WebSocket method works well for basic tasks, CDP is recommended for:
378
+
379
+ - High-quality screenshots
380
+ - Large or complex pages
381
+ - Network debugging
382
+ - Performance analysis
383
+ - Production-ready captures
384
+
385
+ The automatic fallback ensures sweetlink works in all environments, but CDP unlocks its full potential.
@@ -0,0 +1,65 @@
1
+ # UI Verification Mandate
2
+
3
+ **CRITICAL**: Always confirm every UI change with screenshots before considering the task complete.
4
+
5
+ ## Requirements
6
+
7
+ After implementing any visual/UI changes, you MUST:
8
+
9
+ 1. **Take a screenshot** to verify the change renders correctly
10
+ 2. **Compare before/after** when making layout or styling changes
11
+ 3. **Verify at multiple viewports** for responsive design changes (mobile, tablet, desktop)
12
+
13
+ ## Tools
14
+
15
+ ### Sweetlink (Quick Verification)
16
+
17
+ ```bash
18
+ # Basic screenshot
19
+ pnpm sweetlink screenshot --output .tmp/check.png
20
+
21
+ # Screenshot specific element
22
+ pnpm sweetlink screenshot --selector ".card" --output .tmp/card.png
23
+
24
+ # Screenshot at specific URL
25
+ pnpm sweetlink screenshot --url "http://localhost:3000/page" --output .tmp/page.png
26
+
27
+ # Check console for errors
28
+ pnpm sweetlink logs --filter error
29
+ ```
30
+
31
+ ### Playwright MCP (Complex Scenarios)
32
+
33
+ Use Playwright MCP tools (`mcp__playwright__*`) when you need:
34
+
35
+ - Browser interactions (click, type, hover)
36
+ - Multi-step verification flows
37
+ - Network request inspection
38
+ - Dialog handling
39
+
40
+ ## Why This Matters
41
+
42
+ 1. **Catches rendering bugs** - CSS/layout issues not visible in code
43
+ 2. **Prevents regressions** - Ensures changes don't break existing UI
44
+ 3. **Validates responsive behavior** - Layout at different breakpoints
45
+ 4. **Confirms user expectations** - Visual proof implementation matches requirements
46
+
47
+ ## Workflow
48
+
49
+ ```
50
+ 1. Implement UI change
51
+ 2. Run dev server (if not running)
52
+ 3. Take screenshot(s)
53
+ 4. Review screenshot(s) - does it look correct?
54
+ 5. If issues found → fix and repeat from step 3
55
+ 6. If correct → task complete
56
+ ```
57
+
58
+ ## Common Viewport Sizes
59
+
60
+ | Breakpoint | Width | Use Case |
61
+ |------------|-------|----------|
62
+ | Mobile | 375px | Phone portrait |
63
+ | Tablet | 768px | iPad portrait |
64
+ | Desktop | 1280px | Laptop |
65
+ | Wide | 1920px | Desktop monitor |