Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

fix: text pick first visible candidate in readability root selection

Bosch38a29e9ab26a
diff --git a/docs/endpoints.md b/docs/endpoints.md
index 80b52073..523b7f12 100644
--- a/docs/endpoints.md
+++ b/docs/endpoints.md
@@ -161,6 +161,8 @@ Text query parameters:
- `mode=raw`
- `format`
+`/text` default mode picks the first **visible** `<article>` / `[role="main"]` / `<main>` (skips `display:none`) and strips nav/footer/ads. Use `mode=raw` for full `innerText`, or `/snapshot` for structured UI text like prices and button labels.
+
Find body fields:
- `query`
diff --git a/internal/assets/readability.js b/internal/assets/readability.js
index 2bc77365..b531e1f3 100644
--- a/internal/assets/readability.js
+++ b/internal/assets/readability.js
@@ -7,9 +7,30 @@
'#Lb4nn', '.language-selector', '.locale-selector',
'[data-language-picker]', '#langsec-button'];
- let root = document.querySelector('article') ||
- document.querySelector('[role="main"]') ||
- document.querySelector('main');
+ // Pick the first VISIBLE candidate root. Pages may contain multiple
+ // <main> or [role="main"] elements and toggle between them with
+ // display:none (common SPA pattern). querySelector() returns the first
+ // in document order regardless of visibility, which produces stale
+ // content after in-place DOM updates.
+ const isVisible = (el) => {
+ if (!el || !el.isConnected) return false;
+ const style = window.getComputedStyle(el);
+ if (style.display === 'none' || style.visibility === 'hidden') return false;
+ const rect = el.getBoundingClientRect();
+ return rect.width > 0 || rect.height > 0;
+ };
+
+ const firstVisible = (selector) => {
+ const nodes = document.querySelectorAll(selector);
+ for (const n of nodes) {
+ if (isVisible(n)) return n;
+ }
+ return null;
+ };
+
+ let root = firstVisible('article') ||
+ firstVisible('[role="main"]') ||
+ firstVisible('main');
if (!root) {
root = document.body.cloneNode(true);
diff --git a/skills/pinchtab/references/api.md b/skills/pinchtab/references/api.md
index 1217a7b3..f89e3c4d 100644
--- a/skills/pinchtab/references/api.md
+++ b/skills/pinchtab/references/api.md
@@ -153,6 +153,8 @@ curl "/text?mode=raw"
Returns `{url, title, text}`. Cheapest option (~1K tokens for most pages).
+Default mode picks the first **visible** `<article>` / `[role="main"]` / `<main>` (skips `display:none`) and strips nav/footer/ads. Use `mode=raw` for full `innerText`, or `/snapshot` for structured UI text like prices and button labels.
+
## PDF export
Prefer returning base64 or raw bytes unless the user explicitly wants a file written to disk.