You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Web浏览器中检测Apple Vision Pro设备?

Apple Vision Pro 设备检测问题

我使用以下代码检测浏览器是否适配XR,但在Apple Vision Pro设备上无法生效,尝试添加/visionpro/i.test(userAgent)检测逻辑后依然无法识别,求可行的Vision Pro设备检测方法:

Vr.prototype.isMobileDevice = function() {
var userAgent = navigator.userAgent || window.opera;

// Updated regular expressions for broader device detection, including hypothetical 'visionpro'
return /android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos/i.test(userAgent)
    || /iPhone|iPad|iPod/i.test(userAgent);
    // Custom check for Vision Pro
    // Additional checks can be added here based on further unique characteristics
}

可行的检测方案

1. 结合平台标识与WebXR API检测

Apple Vision Pro的Safari不会在UA字符串中直接暴露"visionpro",但可以通过平台标识+WebXR支持性组合判断:

async function isVisionPro() {
  // Vision Pro 会伪装成 MacIntel 平台,且支持WebXR
  if (navigator.platform !== 'MacIntel' || !navigator.xr) return false;
  
  try {
    // 验证是否支持沉浸式AR会话(Vision Pro核心XR能力)
    return await navigator.xr.isSessionSupported('immersive-ar');
  } catch (e) {
    return false;
  }
}

注意这是异步方法,需要在调用时处理Promise。

2. 优先检测XR能力而非设备标识

相比依赖UA字符串,直接检测设备的WebXR支持性更可靠,也能兼容其他XR设备:

async function supportsXRImmersiveSession() {
  if (!navigator.xr) return false;
  try {
    // 检测是否支持沉浸式AR/VR会话
    return await navigator.xr.isSessionSupported('immersive-ar') || 
           await navigator.xr.isSessionSupported('immersive-vr');
  } catch (err) {
    return false;
  }
}

// 改造原有检测方法
Vr.prototype.isXRSupportedDevice = async function() {
  const isMobile = /android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos/i.test(navigator.userAgent)
    || /iPhone|iPad|iPod/i.test(navigator.userAgent);
  
  const supportsXR = await supportsXRImmersiveSession();
  
  return isMobile || supportsXR;
}

3. 补充UA字符串的隐藏特征

Vision Pro的UA会包含Mac OS X 10_16(伪装成MacOS),同时排除iOS设备标识,可作为辅助检测:

function isVisionProUA() {
  const userAgent = navigator.userAgent;
  return /Mac OS X 10_16/i.test(userAgent) && 
         /Safari/i.test(userAgent) && 
         !/iPhone|iPad|iPod/i.test(userAgent);
}

这种方式依赖UA伪装规则,建议和WebXR检测结合使用,避免未来规则变更导致失效。

内容的提问来源于stack exchange,提问作者Lenvanthis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 05:50:04