I have a solution, but it feels pretty fragile.
Check the OS, since Apple Silicon only exists with 10_15 or higher:
navigator.userAgent.match(/OS X 10_([789]|1[01234])/)
Check the GPU using webgl:
var w = document.createElement("canvas").getContext("webgl");
var d = w.getExtension('WEBGL_debug_renderer_info');
var g = d && w.getParameter(d.UNMASKED_RENDERER_WEBGL) || "";
if (g.match(/Apple/) && !g.match(/Apple GPU/)) {
...definitely arm...
}
If you see Apple GPU, then it's Safari which hides the GPU to prevent fingerprinting. Dig into capabilities:
if (w.getSupportedExtensions().indexOf("WEBGL_compressed_texture_s3tc_srgb") == -1) {
...probably arm...
}
(I compared the capabilities of my MacBook Pro to a new M1 Air, and that one is missing on the Air. All others were identical.)
The approach I'm taking is to give the user a choice, but use this test to choose the default.
If anyone has another idea of something that might be peculiar to help narrow down if it's an M1, I'm happy to experiment...
Update: As Romain points out in the comments, Apple added support for the missing extension in Big Sur, so this isn't working now (in Safari; it still works in Chrome & Firefox).