{"version":3,"file":"browser-CMFCxUv7.mjs","names":[],"sources":["../../src/browser.ts"],"sourcesContent":["/**\n * Checks if the window object is defined. You can also use this to check if something is happening on the client side.\n *\n * @returns\n */\nexport function inBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nconst botAgents = [\n 'bot',\n 'spider',\n 'crawl',\n 'APIs-Google',\n 'AdsBot',\n 'Googlebot',\n 'mediapartners',\n 'Google Favicon',\n 'FeedFetcher',\n 'Google-Read-Aloud',\n 'DuplexWeb-Google',\n 'googleweblight',\n 'bing',\n 'yandex',\n 'baidu',\n 'duckduck',\n 'yahoo',\n 'ecosia',\n 'ia_archiver',\n 'facebook',\n 'instagram',\n 'pinterest',\n 'reddit',\n 'slack',\n 'twitter',\n 'whatsapp',\n 'youtube',\n 'semrush',\n];\nconst botAgentRegex = new RegExp(botAgents.join('|'), 'i');\n\n/**\n * Checks if the user agent is a bot.\n *\n * @param userAgent - Any user agent string\n * @returns\n */\nexport function userAgentIsRobot(userAgent: string): boolean {\n return !userAgent ? false : botAgentRegex.test(userAgent);\n}\n\n/**\n * Checks if the current environment is a browser and the user agent is not a bot.\n *\n * @returns\n */\nexport function isValidBrowser(): boolean {\n const navigator = inBrowser() ? window?.navigator : null;\n if (!navigator) {\n return false;\n }\n return !userAgentIsRobot(navigator?.userAgent) && !navigator?.webdriver;\n}\n\n/**\n * Checks if the current environment is a browser and if the navigator is online.\n *\n * @returns\n */\nexport function isBrowserOnline(): boolean {\n const navigator = inBrowser() ? window?.navigator : null;\n if (!navigator) {\n return false;\n }\n\n // Some environments (e.g. React Native) define a Navigator object but do not\n // implement navigator.onLine as a boolean. Default to online in those cases.\n if (typeof navigator.onLine !== 'boolean') {\n return true;\n }\n\n // navigator.onLine is the standard API and is reliable for detecting\n // complete disconnection (airplane mode, WiFi off, etc.).\n // The experimental navigator.connection API (rtt/downlink) was previously\n // used as a secondary signal, but it reports zero values in headless browsers\n // and CI environments even when connected, causing false offline detection.\n return !!navigator.onLine;\n}\n\n/**\n * Runs `isBrowserOnline` and `isValidBrowser` to check if the current environment is a valid browser and if the navigator is online.\n *\n * @returns\n */\nexport function isValidBrowserOnline(): boolean {\n return isBrowserOnline() && isValidBrowser();\n}\n"],"mappings":";;;;;;AAKA,SAAgB,YAAqB;AACnC,QAAO,OAAO,WAAW;;AAiC3B,MAAM,gBAAgB,IAAI,OA9BR;CAChB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAC0C,KAAK,IAAI,EAAE,IAAI;;;;;;;AAQ1D,SAAgB,iBAAiB,WAA4B;AAC3D,QAAO,CAAC,YAAY,QAAQ,cAAc,KAAK,UAAU;;;;;;;AAQ3D,SAAgB,iBAA0B;CACxC,MAAM,YAAY,WAAW,GAAG,QAAQ,YAAY;AACpD,KAAI,CAAC,UACH,QAAO;AAET,QAAO,CAAC,iBAAiB,WAAW,UAAU,IAAI,CAAC,WAAW;;;;;;;AAQhE,SAAgB,kBAA2B;CACzC,MAAM,YAAY,WAAW,GAAG,QAAQ,YAAY;AACpD,KAAI,CAAC,UACH,QAAO;AAKT,KAAI,OAAO,UAAU,WAAW,UAC9B,QAAO;AAQT,QAAO,CAAC,CAAC,UAAU;;;;;;;AAQrB,SAAgB,uBAAgC;AAC9C,QAAO,iBAAiB,IAAI,gBAAgB"}