Chrome DevTools
Start Dev Server with Debugging
Connect DevTools
DevTools Features
Console
View
console.log() output and errorsSources
Set breakpoints and step through code
Network
Inspect fetch requests and responses
Memory
Profile memory usage and heap snapshots
VS Code Debugging
Configuration
Create.vscode/launch.json:
.vscode/launch.json
Start Debugging
- Launch Mode
- Attach Mode
- Open the Debug panel (Cmd/Ctrl + Shift + D)
- Select Wrangler Dev from the dropdown
- Click the green play button or press F5
- Set breakpoints in your Worker code
- Trigger your Worker
Logging
Console Logging
Standard console methods work in Workers:src/index.ts
wrangler devterminal- Chrome DevTools console
- Production logs (via Logpush/Tail Workers)
Structured Logging
src/index.ts
Log Levels
Control log verbosity:debug- All logs including debug infoinfo- Informational messageslog- Standard logswarn- Warnings onlyerror- Errors onlynone- No logs
wrangler.json
Breakpoint Debugging
Setting Breakpoints
In your code:src/index.ts
Conditional Breakpoints
Right-click a line number in DevTools → “Add conditional breakpoint”:Watch Expressions
Add watch expressions in DevTools to monitor variables:Inspector Configuration
Custom Inspector Port
wrangler.json
Custom Inspector Host
wrangler.json
Disable Inspector
wrangler.json
Production Debugging
Tail Workers
Stream real-time logs from production Workers:Tail Worker Consumers
Create a Worker to process logs:tail-consumer.ts
wrangler.json:
wrangler.json
Logpush
Forward logs to external services (Enterprise only):wrangler.json
- Datadog
- New Relic
- Splunk
- Sumo Logic
- S3
- Google Cloud Storage
Error Tracking
Capture Errors
src/index.ts
Integration with Error Services
- Sentry
- Custom Service
Performance Debugging
Timing API
src/index.ts
Custom Metrics
src/index.ts
Debugging Specific Features
Durable Objects
src/counter.ts
Service Bindings
src/index.ts
WebSockets
src/index.ts
Best Practices
1. Use Descriptive Logs
2. Don’t Log Sensitive Data
3. Use Log Levels Appropriately
4. Add Context to Errors
5. Clean Up Debug Code
Use environment variables:Troubleshooting
DevTools Not Connecting
-
Check the inspector port:
- Verify no firewall blocking port 9229
-
Try a different port:
Breakpoints Not Hitting
- Ensure source maps are enabled (default)
- Check that your code is actually running
- Verify breakpoint is on an executable line
- Clear DevTools cache and reload
Missing Logs
-
Check log level:
-
Ensure
console.log()is not commented out - Verify logs appear in DevTools console
See Also
Local Development
Develop Workers locally
Testing
Test Workers with vitest