mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-09-27 07:58:45 +03:00
[submodule:helpers] Add an optional parameter in isAppleSilicon()
that flags the use of feature detection
This commit is contained in:
parent
75690f16cc
commit
19e5d322e2
2
src/helpers/ua-parser-helpers.d.ts
vendored
2
src/helpers/ua-parser-helpers.d.ts
vendored
@ -5,7 +5,7 @@
|
||||
import { IResult } from "../main/ua-parser";
|
||||
|
||||
declare function getDeviceVendor(model: string): string | undefined;
|
||||
declare function isAppleSilicon(res: IResult): boolean;
|
||||
declare function isAppleSilicon(res: IResult, useFeatureDetection?: boolean): boolean;
|
||||
declare function isBot(res: IResult): boolean;
|
||||
declare function isChromeFamily(res: IResult): boolean;
|
||||
declare function isElectron(): boolean;
|
||||
|
@ -15,11 +15,12 @@ const { isStandalonePWA } = require('is-standalone-pwa');
|
||||
|
||||
const getDeviceVendor = (model) => UAParser(`Mozilla/5.0 (Linux; Android 10; ${model}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.0.0 Safari/537.36`).device.vendor;
|
||||
|
||||
const isAppleSilicon = (res) => {
|
||||
const isAppleSilicon = (res, useFeatureDetection) => {
|
||||
if (res.os.is(OS.MACOS)) {
|
||||
if (res.cpu.is(CPU.ARM)) {
|
||||
return true;
|
||||
}
|
||||
if (useFeatureDetection) {
|
||||
try {
|
||||
const canvas = document.createElement('canvas');
|
||||
const webgl = canvas.getContext('webgl2') || canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
|
||||
@ -32,6 +33,7 @@ const isAppleSilicon = (res) => {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user