--- name: headless-cdp-qa description: Use when browser_exec screenshots time out. Stdlib CDP QA. version: 1.0.0 author: HamaratLabs license: MIT --- # Headless Chrome QA via raw CDP (stdlib only) When the shared `browser_exec` tab times out on `Page.captureScreenshot` (seen on a Mac: visible Chrome window small/occluded, even after `Page.bringToFront`), drive a private headless Chrome with `scripts/cdp.py` (socket + http.client + json; no websocket lib, no puppeteer needed). ## Use 1. Serve the site: `terminal(background=True)` `python3 -m http.server --bind 127.0.0.1` from the repo root; kill your own PID at the end. 2. Copy `scripts/cdp.py` next to the project's QA scripts (e.g. `//araclar/`), then: ```python import sys; sys.dont_write_bytecode = True # no __pycache__ in repo (deleting needs approval) from cdp import Tarayici with Tarayici() as t: s = t.sayfa(390, 844) # <600 px -> mobile + DPR 2 s.git(url); s.js("document.documentElement.scrollWidth"); s.ekran(path, tam=True); s.hatalar ``` 3. Write QA as script files and run `python3 file.py`: longer flows are easier to review, rerun and keep in the repo that way. If your agent runtime asks for approval before running a command, wait for the user's approval; do not look for another way to run it. ## Pitfalls (each cost a rerun) - Any fixed port (including the cdp.py default) may collide with another Chrome already listening on a remote-debugging port: `Tarayici()` then silently attaches to that browser and opens tabs in it. Always pass a task-unique port (`Tarayici(port=94xx)`) and set `CDP_PROFILE` to a task scratch dir before importing; check with `ps aux | grep remote-debugging-port=`. Close any tabs you opened by mistake via `curl http://127.0.0.1:/json/close/`. - Persistent profile keeps HTTP cache: CSS edits look ignored. `Sayfa` enables `Network.setCacheDisabled`; keep it. - Full-page shot taken while scrolled renders sticky headers mid-page: `ekran(tam=True)` scrolls to 0 first. - Sticky sidebars (height 100vh) look clipped in full-page shots; that is an artifact, note it in the report instead of "fixing" it. - `hatalar` collects `Runtime.exceptionThrown`, `console.error` and `Log.entryAdded` errors (catches 404s, e.g. missing favicon: add an inline data-URI icon). - Real key presses (Ctrl/Cmd+K palettes, arrows, Enter) need `Input.dispatchKeyEvent` keyDown+keyUp with `windowsVirtualKeyCode` and `modifiers` (2=Ctrl, 4=Meta); text via `Input.insertText`. - localStorage persists across runs in the scratch profile: clear it at the start of flow tests. - Proving a CSS overlap/spacing fix needs numbers, not a look: when a screenshot-reading tool is unavailable, compare `getBoundingClientRect()` of the elements in question via `s.js(...)` (or `DOM.getBoxModel` over CDP) and assert a positive gap between their edges. This is deterministic and does not depend on any image-analysis tool being up. ## Audio / Gradio app QA - Launch Chrome with `--mute-audio --autoplay-policy=no-user-gesture-required` so CDP clicks can play audio silently; drop `--hide-scrollbars` when checking Windows-like layout width. - Gradio's waveform player (WaveSurfer) keeps its `