有没有办法在 JavaScript 中检测 Apple Silicon Mac?navigator
中的属性似乎不是很有帮助,例如,navigator.platform
设置为 MacIntel
和用户代理完全相同。
原因部分:我有两个可用的软件版本,用于 Intel 和 Apple Silicon。询问用户“你的 Mac 是 Apple Silicon 还是 Intel?”不是很好。
最佳答案
我有一个解决方案,但感觉很脆弱。
检查操作系统,因为 Apple Silicon 仅存在于 10_15 或更高版本:
navigator.userAgent.match(/OS X 10_([789]|1[01234])/)
使用 webgl 检查 GPU: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...
}
如果您看到 Apple GPU,那么它就是 Safari,它隐藏了 GPU 以防止指纹识别。挖掘能力:if (w.getSupportedExtensions().indexOf("WEBGL_compressed_texture_s3tc_srgb") == -1) {
...probably arm...
}
(我将我的 MacBook Pro 的功能与新的 M1 Air 进行了比较,但 Air 上没有那个。所有其他的都是相同的。)我正在采取的方法是给用户一个选择,但是使用这个测试来选择默认值。
如果有人有其他想法,如果它是 M1,可能有助于缩小范围,我很乐意尝试......
更新:正如 Romain 在评论中指出的那样,Apple 在 Big Sur 中添加了对缺少的扩展的支持,所以现在这不起作用(在 Safari 中;它仍然在 Chrome 和 Firefox 中有效)。
关于javascript - 在 JavaScript 中检测 Apple Silicon mac,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65146751/