| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- 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
- };
|