import { UAParser } from 'ua-parser-js'; // Constants for browsers const isAndroid=()=>{ try { return window.progressier.detection.isAndroid(); } catch (t) { return false } } const isIOS=()=>{ try { return window.progressier.detection.isIOS(); } catch (t) { return false } } const isMacOs=()=>{ try { return window.progressier.detection.isMacOs(); } catch (t) { return false } } const isWindows=()=>{ try { return window.progressier.detection.isWindows(); } catch (e) { return false } } const isSafari=()=>{ try { return window.progressier.detection.isSafari(); } catch (e) { return false } } const isFirefox=()=>{ try { return window.progressier.detection.isFirefox(); } catch (n) { return false } } const isSamsungInternet=()=>{ try { return window.progressier.detection.isSamsungInternet(); } catch (e) { return false } } const isChromeEdgeOnMacOs=()=>{ try { return window.progressier.detection.isChromeEdgeOnMacOs(); } catch (e) { return false } } const isArc=()=>{ try { return window.progressier.detection.isArc(); } catch (e) { return false } } const isEdge=()=>{ try { return window.progressier.detection.isEdge(); } catch (e) { return false } } const isChrome=()=>{ try { return window.progressier.detection.isChrome(); } catch (r) { return false } } const isOpera=()=>{ try { return window.progressier.detection.isOpera(); } catch (e) { return false } } const supportsNativeiOSPush=()=>{ try { return window.progressier.detection.supportsNativeiOSPush(); } catch (e){ return false; } } const appstore=()=>{ return supportsNativeiOSPush() } const supportsPush=()=>{ try { return window.progressier.detection.supportsPush(); } catch (e){ return false; } } const isFromTwitter=()=>{ try { return window.progressier.detection.isFromTwitter(); } catch (e){ return false; } } const getInAppBrowser=()=>{ try { var t = window.navigator.userAgent; var e = ["wv", "Line/", "FBAN", "FBBV", "FBAV", "FB_IAB", "Instagram", "MicroMessenger", "Twitter", "Kakao", "KAKAO"]; var i = ""; e.forEach(function(e) { if (!t.includes(e)) { return } i = e; }); return i; } catch (n) { return ""; } } const isInAppBrowser=()=>{ try { // return window.progressier.detection.isInAppBrowser(); return getInAppBrowser()!==""; } catch (e){ return false; } } const isInFBBrowser=()=>{ try { let fbua = window.navigator.userAgent.toUpperCase(); let e=["FBAN", "FBBV", "FBAV", "FB_IAB","IAB","FACEBOOK", "INSTAGRAM","WHATSAPP","TELEGRAM"]; for (let i = 0; i < e.length; i++) { if (fbua.includes(e[i]))return true; } return false; } catch (e){ return false; } } export { isInFBBrowser }; const isChromeOS=()=>{ try { return window.progressier.detection.isChromeOS(); } catch (e) { return false } } const isDesktop=()=>{ try { return window.progressier.detection.isDesktop(); } catch (e) { return false } } const isSafariWithPushOnMacOs=()=>{ try { return window.progressier.detection.isSafariWithPushOnMacOs(); } catch (e){ return false } } const isSafariWithInstallationMacOS=()=>{ try { return window.progressier.detection.isSafariWithInstallationMacOS(); } catch (a) { return false } } const canBePushPrompted=()=>{ try { return window.progressier.detection.canBePushPrompted(); } catch (e){ return false } } // PWA 安装/启动判断需要的 isInPc:避免在桌面端走 mobile 引导 const isLinux=()=>{ try { return /Linux/i.test(navigator.platform || navigator.userAgent || "") && !/Android/i.test(navigator.userAgent || ""); } catch (e) { return false; } } const isInPc=()=>{ return isMacOs()||isWindows()||isLinux(); } const isStandalone=()=>{ try { return window.progressier.detection.isStandalone(); } catch (e){ return false } } const iosVersion=()=>{ try { return window.progressier.detection.iosVersion(); } catch (e){ return false } } const recentiOS=()=>{ try { return window.progressier.detection.recentiOS(); } catch (e){ return false } } const isTWA=()=>{ try { return window.progressier.detection.isTWA(); } catch (e){ return false } } const requiresInScopeSw=()=>{ try { return window.progressier.detection.requiresInScopeSw(); } catch (e){ return false } } const isIframe=()=>{ try { return window.progressier.detection.isIframe(); } catch (e){ return false } } const isShowInstallBox=()=>{ if (isStandalone())return false; if (isTWA())return false; return true; } const openProgressierInstall=()=>{ if(window.progressier&&window.progressier.flow)window.progressier.flow.init("install",true) } const openUrlUseChrome=(url="")=>{ try { if (url==null||url==="")url=window.location.href; if (global.BFP!=null&&global.BFP!==""){ if (url.indexOf("?")===-1)url+="?bfp="+global.BFP; else url+="&bfp="+global.BFP; } if (isTWA())return; if (isIOS()){ let r = "googlechromes://" + url.replace(/^https?:\/\//, ""); window.location.href = r } else if (isAndroid()){ const r = url.split(":")[0]; let l = url.replace(/^https?:\/\//, ""); window.location.href = "intent://".concat(l, "#Intent;scheme=").concat(r, ";package=com.android.chrome;end") } } catch (e){ return false; } } const openUrlUseExternal=(url="")=>{ try { if (url==null||url==="")url=window.location.href; if (isAndroid()) openUrlUseChrome(url); else window.open(url,"_blank"); } catch(e){ return false; } } export { openUrlUseExternal, isAndroid, isIOS, isMacOs, isWindows, isSafari, isFirefox, isSamsungInternet, isChromeEdgeOnMacOs, isArc, isEdge, isChrome, isOpera, supportsNativeiOSPush, appstore, supportsPush, isFromTwitter, isInAppBrowser, isChromeOS, isDesktop, isSafariWithPushOnMacOs, isSafariWithInstallationMacOS, canBePushPrompted, isStandalone, iosVersion, recentiOS, isTWA, requiresInScopeSw, isIframe, isShowInstallBox, openUrlUseChrome, openProgressierInstall, getInAppBrowser, isInPc, isLinux };