From 74ff9fdcb8b49a021b63ac2e6b0191e29754d0f3 Mon Sep 17 00:00:00 2001 From: Igor Soarez Date: Fri, 6 Nov 2026 03:17:13 +0000 Subject: castle-search: read Google results again by resolving its /goto links Google now wraps every result as google.com/goto?url=. 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. --- castle-search/src/extract.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'castle-search/src/extract.ts') 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=` * - Bing: `//bing.com/ck/a?…&u=a1` * - * Google and Brave link straight out and need no unwrapping. + * Brave links straight out. Google wraps results in `/goto?url=` + * 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; }; -- cgit v1.2.3