Use Bowser to Detect Mobile

This commit is contained in:
Alexandru Branza 2023-05-29 17:38:13 +03:00
parent 242a277484
commit c9347885e0

View file

@ -1,24 +1,11 @@
// Copyright (C) 2017-2022 Smart code 203358507
function iOS() {
return [
'iPad Simulator',
'iPhone Simulator',
'iPod Simulator',
'iPad',
'iPhone',
'iPod'
].includes(navigator.platform)
|| (navigator.userAgent.includes('Mac') && 'ontouchend' in document);
}
const Bowser = require('bowser');
function android() {
const ua = navigator.userAgent.toLowerCase();
return ua.indexOf('android') > -1;
}
const browser = Bowser.parse(window.navigator?.userAgent || '');
module.exports = () => {
if (iOS()) return 'ios';
if (android()) return 'android';
if (browser?.os?.name === 'iOS') return 'ios';
if (browser?.os?.name === 'Android') return 'android';
return false;
};