Browser Automation Debugging Guide
Overview
When lsbot runs browser automation, it can now capture detailed debugging information to help diagnose issues. This guide explains how to enable and use the debug features.
Quick Start
Enable debug mode when starting the router:
Debug Features
1. Error Screenshots
When browser actions fail (click, type, etc.), the system automatically captures screenshots of the current page state.
Location: Screenshots are saved to the debug directory with descriptive names:
error_click_resolve_ref42_2026-02-08_14-30-45.123.png- Failed to resolve ref 42error_click_not_interactable_ref15_2026-02-08_14-30-46.456.png- Element not clickableerror_type_focus_ref8_2026-02-08_14-30-47.789.png- Failed to focus input
2. Fresh Snapshots in Errors
When an action fails, the AI automatically receives a fresh snapshot of the current page state, showing:
- What elements are currently visible
- Updated ref numbers
- Current page structure
This helps the AI understand what changed and adjust its strategy.
3. Automatic Retry
When a ref is not found (page changed), the system automatically:
- Captures a fresh snapshot
- Updates the ref mappings
- Retries the action with the updated refs
Success message example:
Configuration
Command-Line Flags
| Flag | Description | Default |
|---|---|---|
--debug | Enable browser debug mode | false |
--debug-dir <path> | Directory for debug screenshots | /tmp/lsbot (Unix)%TEMP%\lsbot (Windows) |
Environment Variables
| Variable | Description | Example |
|---|---|---|
BROWSER_DEBUG | Enable debug mode | 1 or true |
BROWSER_DEBUG_DIR | Debug directory path | /tmp/lingti-debug |
Platform Defaults
- macOS/Linux:
/tmp/lsbot/ - Windows:
%TEMP%\lsbot\
Debug Workflow
Normal Operation (No Debug)
With Debug Mode
Debugging Common Issues
Issue: "ref not found"
Cause: Page changed after snapshot (navigation, AJAX, animations)
Automatic Fix: System retries with fresh snapshot
Manual Fix: Run browser_snapshot again before retrying the action
Issue: "element not interactable"
Cause: Element is hidden, covered, or not yet loaded
Debug: Check the error screenshot to see:
- Is the element visible?
- Is there a modal/overlay covering it?
- Did the page finish loading?
Fix:
- Wait for page to load
- Close overlays
- Scroll element into view
- Use a different selector
Issue: "click failed"
Cause: Element cannot be clicked (disabled, removed, etc.)
Debug: Error screenshot shows the exact page state when click failed
Fix:
- Check if element is disabled
- Wait for element to become enabled
- Find alternative way to achieve the goal
Best Practices
- Always check screenshots first - They show exactly what the automation saw
- Look for patterns - Multiple failures at the same step? Check timing/waits
- Compare before/after - Screenshots help identify what changed
- Clean up debug directory - Old screenshots can accumulate quickly
Example: Debugging a Login Flow
User Request
"Go to example.com and log in with my credentials"
Debug Session
AI Actions:
browser_navigate→ example.combrowser_snapshot→ Gets refs for all elementsbrowser_click ref=12→ Click username field- ❌ Error: "element not interactable"
- Screenshot saved:
/tmp/login-debug/error_click_not_interactable_ref12_...png - Shows: Cookie consent modal is covering the form!
- Screenshot saved:
- AI analyzes fresh snapshot, sees modal
browser_click ref=45→ Accept cookiesbrowser_click ref=12→ ✅ Username field focusedbrowser_type ref=12 text="user"→ ✅ Typed usernamebrowser_type ref=13 text="pass" submit=true→ ✅ Logged in
Debug Files Created
Reviewing the screenshot shows:
- Cookie modal was covering the login form
- AI correctly identified and closed the modal
- Login succeeded after modal was removed
Performance Impact
Debug mode has minimal performance impact:
- Screenshots are only captured on errors
- No screenshots during successful operations
- Disk I/O is asynchronous
Typical overhead: < 100ms per error
Disabling Debug Mode
Simply restart without the --debug flag:
Or unset the environment variable:
Troubleshooting
Debug directory not created
Check permissions:
No screenshots being saved
Verify debug mode is enabled:
- Check command-line flags
- Check environment variables
- Look for "Browser debug mode enabled" in startup logs
Screenshots are blank
Possible causes:
- Page hasn't loaded yet
- Browser is in headless mode (expected)
- Page rendering issue
Summary
Debug mode provides three key benefits:
- Visual feedback - Screenshots show exactly what went wrong
- Automatic recovery - Retry with fresh snapshots when refs are stale
- Context for AI - AI sees current page state and can adapt strategy
Enable it during development and testing, disable in production for optimal performance.