/** * Detects common search-engine results pages so they can be allowed while destinations stay blocked. * @param {string} url * @returns {boolean} */ export function isSearchEngineResultsPage(url) { if (!url || typeof url !== 'string') { return false; } try { const u = new URL(url); if (u.protocol !== 'http:' && u.protocol !== 'https:') { return false; } const host = u.hostname.replace(/^www\./, '').toLowerCase(); const path = u.pathname.toLowerCase(); const hasQuery = Boolean(u.search && u.search.length > 1); if (host === 'google.com' || host.endsWith('.google.com')) { return path.startsWith('/search'); } if (host.endsWith('bing.com')) { return path.startsWith('/search'); } if (host === 'search.yahoo.com' || (host.endsWith('.yahoo.com') && path.includes('/search'))) { return true; } if (host === 'duckduckgo.com') { return path === '/' || path === '/lite' || path.startsWith('/?') || hasQuery; } if (host === 'ecosia.org') { return path.startsWith('/search'); } if (host === 'search.brave.com') { return path.startsWith('/search') || hasQuery; } if (host === 'yandex.com' || host.endsWith('.yandex.com')) { return path.startsWith('/search'); } if (host === 'startpage.com' || host === 'www.startpage.com') { return path.startsWith('/search') || path.startsWith('/sp/search'); } if (host === 'ask.com') { return path.startsWith('/web'); } if (host === 'baidu.com') { return path.startsWith('/s') || u.search.includes('wd='); } if (host === 'vrilsrc.com' || host === 'www.vrilsrc.com') { return path === '/' || path.startsWith('/search') || hasQuery; } return false; } catch { return false; } }