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

Firefox本地localhost环境中navigator.geolocation.getCurrentPosition失效,但Chrome可正常运行的问题求助

Firefox本地localhost环境中navigator.geolocation.getCurrentPosition失效,但Chrome可正常运行的问题求助

我正在本地(127.0.0.1)测试一个超简单的定位脚本:

window.addEventListener('load',()=>{
    if("geolocation" in navigator){
        navigator.geolocation.getCurrentPosition(successFunction, failureFunction, null);
    } else {
        console.log("Error");
    }
});

successFunction(successObject){
    console.log(successObject);
}

failureFunction(failureObject){
    console.log(failureObject);
}

在Chrome里运行时,successFunction会被正常触发,控制台能打印出GeolocationPosition对象。

但换成Debian 12系统上的Firefox 128.5.0esr(64位)运行时,就会触发failureFunction,控制台输出的GeolocationPositionError信息如下:

GeolocationPositionError {
    code: 2,
    message: "Unknown error acquiring position"
}

其中code:2对应的是POSITION_UNAVAILABLE错误。

这个问题是最近才出现的,之前用Firefox测试完全没碰到过。我已经在Firefox中给本地页面开启了“访问您的位置”权限,而且在公开互联网上的网站使用定位功能完全正常,唯独本地localhost环境出现这个问题。

备注:内容来源于stack exchange,提问作者Brian

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.14 17:28:05