【问题标题】:blocked Access to geolocation was blocked over secure connection with mixed content to https://localhost:3000通过与 https://localhost:3000 的混合内容的安全连接阻止了对地理位置的访问
【发布时间】:2018-11-28 09:22:16
【问题描述】:

我已经实现了devise omniauth 设置,当我使用 Facebook、Twitter 或 google 登录时,html5 geolocation 返回一个 position unavailable error。但是当我以常规devise user 登录时,它工作得很好!使用社交媒体帐户登录时,如何允许访问我的 rails 应用程序上的html5 geolocation?

function getLocation() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(setGeoCookie,showError);
    } else {
        alert("Geolocation is not supported by this browser.");
    }
}


function showError(error) {
switch(error.code) {
    case error.PERMISSION_DENIED:
        window.location = window.location;
        window.alert("Permission denied");
        break;
    case error.POSITION_UNAVAILABLE:
        window.location = window.location;
        window.alert("Location information is unavailable.");
        break;
    case error.TIMEOUT:
        window.location = window.location;
        window.alert("The request to get user location timed out.");

        break;
    case error.UNKNOWN_ERROR:
        window.location = window.location;
        window.alert("An unknown error occurred.");
        break;
}
location.reload();
}

更新 1

我将代码更改为以下内容,但在浏览器控制台中出现以下错误:

Origin does not have permission to use Geolocation service
[blocked] Access to geolocation was blocked over secure connection with mixed content to https://localhost:3000.


function getLocation() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(success, error, options);
    } else {
        alert("Geolocation is not supported by this browser.");
    }
}


var options = {
    enableHighAccuracy: true,
    timeout: 5000,
    maximumAge: 0
};

function success(pos) {
    var crd = pos.coords;

    console.log('Your current position is:');
    console.log(`Latitude : ${crd.latitude}`);
    console.log(`Longitude: ${crd.longitude}`);
    console.log(`More or less ${crd.accuracy} meters.`);
}

function error(err) {
    console.warn(`ERROR(${err.code}): ${err.message}`);
}

关于如何解除阻止的任何想法?

【问题讨论】:

  • 你是在本地主机上运行它吗?如果不是,您的网站正在通过 http 从 localhost 加载一些资产,迫使浏览器确定该网站不安全,并拒绝访问地理位置。此外,这是一个 javascript 问题,而不是 RoR 问题。
  • 感谢@Tim Lawrenz 的回复。我在https://localhost:3000 上运行它,如下所示:rails server puma -b 'ssl://0.0.0.0:3000?key=server.key&cert=server.crt'。我怎样才能弄清楚确切的问题是什么?

标签: javascript ruby-on-rails geolocation omniauth


【解决方案1】:

这不是 Rails 问题,而是 Javascript 问题。在您的模板、CSS 或 Javascript 中的某处,您从 http 而不是 https 加载某些内容。使用浏览器的检查器找出罪魁祸首。

【讨论】:

    猜你喜欢
    • 2018-03-02
    • 2017-11-23
    • 2020-08-22
    • 2021-04-23
    • 2020-11-11
    • 1970-01-01
    • 2014-01-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多