Debug Logging¶
Learn how to effectively debug your scripts using logging.
Available Logging Functions¶
debug_log(message)¶
Enhanced logging with [Script] prefix for visibility.
debug_log("Starting navigation")
await page.goto('https://example.com')
debug_log("Navigation complete")
print(*args)¶
Standard Python print function.
Automatic Logging¶
The executor provides automatic verbose logging:
- [Navigation] - Page navigation and loading events
- [Network] - HTTP requests and responses
- [Browser Console] - Browser console messages
- [Script] - Your
debug_log()messages
Best Practices¶
Track Progress¶
debug_log("Step 1: Login")
await login()
debug_log("Step 2: Navigate to data page")
await page.goto('/data')
debug_log("Step 3: Extract data")
data = await extract_data()
debug_log("Complete!")
Log Variables¶
count = await page.locator('.item').count()
debug_log(f"Found {count} items")
for i, item in enumerate(items):
debug_log(f"Processing item {i+1}/{len(items)}")
Before/After Operations¶
debug_log("About to click submit button")
await button.click()
debug_log("Submit button clicked successfully")
Debugging Hangs¶
When a script hangs, check the logs for the last message before it stopped:
[Script] Looking for download button
[Script] Found 1 button(s)
[Script] About to click button
(hangs here - button click is stuck)
This tells you the click() operation is where the script hung.