--- id: "5f07c543-03d1-4221-b190-de5a8a8c5d66" name: "Probing Strategy" micro_summary: "Step-by-step DOM inspection pattern: single-line JS checks → IIFE extraction → data-* attributes → text vs HTML → JSON.stringify for structured data" status: "in_progress" see_also: [] scope: "How to run browser-harness -c, js() state accumulation, and the probing strategy" --- ## Running browser-harness -c The `-c` argument runs **Python**, not JavaScript. This is the #1 source of errors. ```bash browser-harness -c ' wait_for_load() wait(1) result = js("document.querySelector(\".item\").textContent") print(result) ' ``` **Quote nesting:** outer `'` for bash, inner `"` for JS strings. ## js() accumulates state `js()` evaluates in the **same global scope** across calls. Variables declared in one call persist. - **Single-line expressions:** fine as-is — no state to clash. ```python js("document.querySelectorAll(\".item\").length") ``` - **Multi-line code:** wrap in an **IIFE** to isolate scope. ```python js("""(function() { const items = document.querySelectorAll(".planner-item"); const results = []; for (let i = 0; i < 5; i++) { const el = items[i]; results.push({ text: el.textContent.substring(0, 100) }); } return JSON.stringify(results); })()""") ``` **Without the IIFE**, `const items` fails on the second call with `SyntaxError: Identifier 'items' has already been declared`. ## Probing strategy 1. **Single-line JS** for quick checks: `js("document.querySelector('.item').innerHTML")` 2. **IIFE-wrapped multi-line** for structured extraction. 3. **Inspect `data-*` attributes** for structured data (`data-testid`, `data-cid`, etc.). 4. **Use `innerText`** for human-readable text, **`innerHTML`** for DOM structure. 5. **`JSON.stringify()`** for returning structured data from JS to Python. --- ### 2026-08-15 01:34 UTC ## 2026-08-15 — v0.1.8 correction The `-c` section above is historical. Send the same Python wrapper through stdin with a heredoc. This removes the shell's nested Python argument quoting layer; JavaScript still belongs inside `js(...)`, and IIFEs remain useful for multi-line JavaScript state isolation.