diff options
| author | Igor Soarez <igor@soarez.org> | 2026-11-06 03:17:13 +0000 |
|---|---|---|
| committer | Igor Soarez <igor@soarez.org> | 2026-11-06 03:17:16 +0000 |
| commit | 74ff9fdcb8b49a021b63ac2e6b0191e29754d0f3 (patch) | |
| tree | bab1e3995f1a19762086bdf5aaac0751fdf7ff2e /castle-search/src/extract.ts | |
| parent | f61c43418d704cccb67132540ed7feceacef1d2a (diff) | |
castle-search: read Google results again by resolving its /goto links
Google now wraps every result as google.com/goto?url=<opaque token>. The
self-host filter discarded all of them, so every Google search failed with
'nothing could be parsed'. Accept /goto, resolve it node-side from the
302 Location, and when Google answers its 'Verifying your request'
interstitial instead, keep the wrapped link and put the displayed
breadcrumb in the snippet.
Diffstat (limited to 'castle-search/src/extract.ts')
| -rw-r--r-- | castle-search/src/extract.ts | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/castle-search/src/extract.ts b/castle-search/src/extract.ts index 8b5c57f..653942b 100644 --- a/castle-search/src/extract.ts +++ b/castle-search/src/extract.ts @@ -35,7 +35,9 @@ * - DuckDuckGo: `//duckduckgo.com/l/?uddg=<percent-encoded target>` * - Bing: `//bing.com/ck/a?…&u=a1<base64url of target>` * - * Google and Brave link straight out and need no unwrapping. + * Brave links straight out. Google wraps results in `/goto?url=<opaque token>` + * that only Google can resolve; those are left alone here and resolved + * node-side by resolve.ts. */ import type { ExtractionConfig } from "./engines.ts"; @@ -45,6 +47,8 @@ export type SearchResult = { title: string; url: string; snippet: string; + /** Google only: the site and breadcrumb as displayed, kept for links that cannot be resolved. */ + display?: string; }; /** What the page script returns in a single round trip. */ @@ -261,8 +265,13 @@ export const buildProbeScript = (config: ExtractionConfig): string => String.raw ).replace(/Read more$/, "").trim(); } + var display = ""; + var siteEl = anchor.querySelector("span.VuuXrf"); + var citeEl = anchor.querySelector("cite"); + display = norm([siteEl && siteEl.innerText, citeEl && citeEl.innerText].filter(Boolean).join(" — ")); + seen[url] = true; - out.push({ title: title, url: url, snippet: snippet.slice(0, 600) }); + out.push({ title: title, url: url, snippet: snippet.slice(0, 600), display: display }); } return out; }; |
