castle-search/src/google-links.ts (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
/**
* Google wraps every outbound result in `https://www.google.com/goto?url=<opaque
* token>`. The token is a protobuf blob with no URL in it and the target appears
* nowhere in the page, so the only way to learn it is to follow the link.
*
* It is followed in Chrome, lazily, one link at a time, when the caller asks
* (see `resolveLink` in search.ts) — not here, and not for every result. A
* plain HTTP client gets Google's "Verifying your request" countdown after a
* handful of requests; the browser, with its own profile, gets the redirect.
*/
const GOTO = /^https?:\/\/(www\.)?google\.(?:com?\.)?[a-z]{2,3}\/goto\?url=[A-Za-z0-9_-]+$/;
/** Only these may be opened by castle_cdp_resolve — it is not a general navigator. */
export const isGoogleGoto = (url: string): boolean => GOTO.test(url);
|