File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ let globalObj = typeof window === 'undefined' ? globalThis : window;
7
7
let Error = globalObj . Error ;
8
8
let messageSecret ;
9
9
10
+ let isAppleSiliconCache = null ;
11
+
10
12
// save a reference to original CustomEvent amd dispatchEvent so they can't be overriden to forge messages
11
13
export const OriginalCustomEvent = typeof CustomEvent === 'undefined' ? null : CustomEvent ;
12
14
export const originalWindowDispatchEvent = typeof window === 'undefined' ? null : window . dispatchEvent . bind ( window ) ;
@@ -258,13 +260,18 @@ export function camelcase(dashCaseText) {
258
260
259
261
// We use this method to detect M1 macs and set appropriate API values to prevent sites from detecting fingerprinting protections
260
262
function isAppleSilicon ( ) {
263
+ // Cache the result since hardware doesn't change
264
+ if ( isAppleSiliconCache !== null ) {
265
+ return isAppleSiliconCache ;
266
+ }
261
267
const canvas = document . createElement ( 'canvas' ) ;
262
268
const gl = canvas . getContext ( 'webgl' ) ;
263
269
264
270
// Best guess if the device is an Apple Silicon
265
271
// https://stackoverflow.com/a/65412357
266
- // @ts -expect-error - Object is possibly 'null'
267
- return gl . getSupportedExtensions ( ) . indexOf ( 'WEBGL_compressed_texture_etc' ) !== - 1 ;
272
+ const compressedTextureValue = gl ?. getSupportedExtensions ( ) ?. indexOf ( 'WEBGL_compressed_texture_etc' ) ;
273
+ isAppleSiliconCache = typeof compressedTextureValue === 'number' && compressedTextureValue !== - 1 ;
274
+ return isAppleSiliconCache ;
268
275
}
269
276
270
277
/**
You can’t perform that action at this time.
0 commit comments