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;
77let Error = globalObj . Error ;
88let messageSecret ;
99
10+ let isAppleSiliconCache = null ;
11+
1012// save a reference to original CustomEvent amd dispatchEvent so they can't be overriden to forge messages
1113export const OriginalCustomEvent = typeof CustomEvent === 'undefined' ? null : CustomEvent ;
1214export const originalWindowDispatchEvent = typeof window === 'undefined' ? null : window . dispatchEvent . bind ( window ) ;
@@ -258,13 +260,18 @@ export function camelcase(dashCaseText) {
258260
259261// We use this method to detect M1 macs and set appropriate API values to prevent sites from detecting fingerprinting protections
260262function isAppleSilicon ( ) {
263+ // Cache the result since hardware doesn't change
264+ if ( isAppleSiliconCache !== null ) {
265+ return isAppleSiliconCache ;
266+ }
261267 const canvas = document . createElement ( 'canvas' ) ;
262268 const gl = canvas . getContext ( 'webgl' ) ;
263269
264270 // Best guess if the device is an Apple Silicon
265271 // 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 ;
268275}
269276
270277/**
You can’t perform that action at this time.
0 commit comments