browser-search
browser-search copied to clipboard
smart-extract: avoid reloading the page for snapshot/text fallbacks; Readability fails on Trusted Types CSP
Problem
smart-extract (Camofox path, no --expr) can load the same page up to three times when Readability returns too little text:
camofox.mjs readabilityopens a tab, runs Readability and (if empty) takes a snapshot in that tab;camofox.mjs snapshotreloads the page just to take a snapshot again;tab open+tab evaluate document.body.innerText+tab closeloads it a third time (three Node processes).
Each reload costs 3–6 s on a Raspberry Pi, and the snapshot and innerText are already available in the first tab for ~1–2 s.
Separately, Readability throws on sites with a Trusted Types CSP (e.g. YouTube): Element.innerHTML setter: Sink type mismatch violation blocked by CSP. The whole readability call then fails, the tab is closed and everything is reloaded.
Proposed change
readability()(client): create a permissivedefaultTrusted Types policy in the extraction tab before running Readability (wrapped intry, so CSPs that forbid it behave as before).camofox.mjs readability <url…> [--min-chars N]: each step is guarded by its owntry/catch; if the text is missing or shorter thanN, take the snapshot andinnerTextin the same tab and return them. Without--min-charsthe output is unchanged.smart-extract: evaluate readability → snapshot → rendered text from that single load, keeping the samesourcevalues. Reload (the old steps 2–3) only if the first attempt failed outright or the poor content looks like a block (HTTP ≥ 400 or an error page), so a challenge can still be retried before escalating to Cloak.
Measured (Raspberry Pi 5, before → after)
| URL | before | after |
|---|---|---|
| x.com/NASA | 7.3 s | 4.1 s |
| youtube.com | 13.2 s | 8.0 s |
| amazon.com | 8.8 s | 4.8 s |
Pages where Readability already succeeds are unchanged (same source and character counts).
Released in v3.2.0.