Skip to content

Commit 3cbe62e

Browse files
committed
Add a best-effort hack to detect Apple Silicon
Cribbed from the UAParser project.
1 parent 1aaabeb commit 3cbe62e

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

index.html

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,22 @@ <h2>Partnered Projects</h2>
506506
case 'amd64': arch = 'x64'; break;
507507
case 'arm64': arch = 'arm64'; break;
508508
case 'ia32': arch = 'x32'; break;
509-
default: return 'other';
509+
default:
510+
if (os === 'macos') {
511+
// Best-effort Apple Silicon detection, lifted from:
512+
// https://github.com/faisalman/ua-parser-js/blob/72c59b53/src/helpers/ua-parser-helpers.js#L21-L42
513+
try {
514+
const canvas = document.createElement('canvas');
515+
const webgl = canvas.getContext('webgl2') || canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
516+
const debug = webgl.getExtension('WEBGL_debug_renderer_info');
517+
const renderer = webgl.getParameter(debug.UNMASKED_RENDERER_WEBGL);
518+
if (renderer.match(/apple m\d/i)) {
519+
return 'macos_arm64';
520+
}
521+
} catch { }
522+
return 'macos_x64';
523+
}
524+
arch = 'x64';
510525
}
511526

512527
return `${os}_${arch}`;

0 commit comments

Comments
 (0)