UNPKG

@clerk/shared

Version:

Internal package utils used by the Clerk SDKs

66 lines (65 loc) 1.46 kB
// src/browser.ts function inBrowser() { return typeof window !== "undefined"; } var botAgents = [ "bot", "spider", "crawl", "APIs-Google", "AdsBot", "Googlebot", "mediapartners", "Google Favicon", "FeedFetcher", "Google-Read-Aloud", "DuplexWeb-Google", "googleweblight", "bing", "yandex", "baidu", "duckduck", "yahoo", "ecosia", "ia_archiver", "facebook", "instagram", "pinterest", "reddit", "slack", "twitter", "whatsapp", "youtube", "semrush" ]; var botAgentRegex = new RegExp(botAgents.join("|"), "i"); function userAgentIsRobot(userAgent) { return !userAgent ? false : botAgentRegex.test(userAgent); } function isValidBrowser() { const navigator = window?.navigator; if (!inBrowser() || !navigator) { return false; } return !userAgentIsRobot(navigator?.userAgent) && !navigator?.webdriver; } function isBrowserOnline() { const navigator = window?.navigator; if (!inBrowser() || !navigator) { return false; } const isNavigatorOnline = navigator?.onLine; const isExperimentalConnectionOnline = navigator?.connection?.rtt !== 0 && navigator?.connection?.downlink !== 0; return isExperimentalConnectionOnline && isNavigatorOnline; } function isValidBrowserOnline() { return isBrowserOnline() && isValidBrowser(); } export { inBrowser, userAgentIsRobot, isValidBrowser, isBrowserOnline, isValidBrowserOnline }; //# sourceMappingURL=chunk-XKTTPTOL.mjs.map