Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions injected/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ let globalObj = typeof window === 'undefined' ? globalThis : window;
let Error = globalObj.Error;
let messageSecret;

let isAppleSiliconCache = null;

// save a reference to original CustomEvent amd dispatchEvent so they can't be overriden to forge messages
export const OriginalCustomEvent = typeof CustomEvent === 'undefined' ? null : CustomEvent;
export const originalWindowDispatchEvent = typeof window === 'undefined' ? null : window.dispatchEvent.bind(window);
Expand Down Expand Up @@ -258,13 +260,18 @@ export function camelcase(dashCaseText) {

// We use this method to detect M1 macs and set appropriate API values to prevent sites from detecting fingerprinting protections
function isAppleSilicon() {
// Cache the result since hardware doesn't change
if (isAppleSiliconCache !== null) {
return isAppleSiliconCache;
}
const canvas = document.createElement('canvas');
const gl = canvas.getContext('webgl');

// Best guess if the device is an Apple Silicon
// https://stackoverflow.com/a/65412357
// @ts-expect-error - Object is possibly 'null'
return gl.getSupportedExtensions().indexOf('WEBGL_compressed_texture_etc') !== -1;
const compressedTextureValue = gl?.getSupportedExtensions()?.indexOf('WEBGL_compressed_texture_etc');
isAppleSiliconCache = typeof compressedTextureValue === 'number' && compressedTextureValue !== -1;
return isAppleSiliconCache;
}

/**
Expand Down
Loading