Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Test and interact with local web applications using native Python Playwright scripts
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
examples/console_logging.py
1from playwright.sync_api import sync_playwright23# Example: Capturing console logs during browser automation45url = 'http://localhost:5173' # Replace with your URL67console_logs = []89with sync_playwright() as p:10browser = p.chromium.launch(headless=True)11page = browser.new_page(viewport={'width': 1920, 'height': 1080})1213# Set up console log capture14def handle_console_message(msg):15console_logs.append(f"[{msg.type}] {msg.text}")16print(f"Console: [{msg.type}] {msg.text}")1718page.on("console", handle_console_message)1920# Navigate to page21page.goto(url)22page.wait_for_load_state('networkidle')2324# Interact with the page (triggers console logs)25page.click('text=Dashboard')26page.wait_for_timeout(1000)2728browser.close()2930# Save console logs to file31with open('/mnt/user-data/outputs/console.log', 'w') as f:32f.write('\n'.join(console_logs))3334print(f"\nCaptured {len(console_logs)} console messages")35print(f"Logs saved to: /mnt/user-data/outputs/console.log")