import sys, io from playwright.sync_api import sync_playwright sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8') FRONTEND_DIR = "D:/code/crm-backend-matt/.scratch/opportunity-verify/frontend" with sync_playwright() as p: browser = p.chromium.launch(headless=True) page = browser.new_page() failed_requests = [] page.on("response", lambda r: failed_requests.append(f"{r.status} {r.url}") if r.status >= 400 else None) page.goto(f"file:///{FRONTEND_DIR}/03-list.html") page.wait_for_load_state("networkidle") page.locator("button").first.click() page.wait_for_timeout(5000) print("=== 失败请求 ===") for r in failed_requests: print(r) # 截图看渲染结果 page.screenshot(path="D:/code/crm-backend-matt/.scratch/opportunity-verify/webapp-03-debug.png", full_page=True) browser.close()