ローカル開発環境(Ubuntu 16.04)のWebサイトで作業していて、ローカルWebサーバーに接続するhttp://localhost.example/経由でChrome(58)でWebサイトをテストしています。このJavascriptの実行localhostのChromeでgetCurrentPosition()およびwatchPosition()の「安全でない原点」エラーが発生するのはなぜですか?
:
$(document).ready(function() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
}
});
は、このエラーをトリガ:
[Deprecation] getCurrentPosition() and watchPosition() no longer work on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS. See https://sites.google.com/a/chromium.org/dev/Home/chromium-security/deprecating-powerful-features-on-insecure-origins for more details.
それはなぜですか?ジオロケーションライブラリ/機能を動作させるには、公開されているWebサイトでHTTPSを実行する必要があることを理解しています。私たちは、HTTPS経由で同様のコードを実行する多くの公開Webサイトを持っています。
しかしdepreciation documentationに従って:
localhost is treated as a secure origin over HTTP, so if you're able to run your server from localhost, you should be able to test the feature on that server.
Javascriptを上記ザ・はhttp://localhost.example/test-page/介してロードHTML本体にインラインで実行されている - なぜ私はChromeで「安全でない起源」エラーを取得していますか?
Firefox(53)は、ブラウザのアクセス先のプロンプトを期待どおりに表示します。
httpsを使用してローカルマシンから実行できますか? – ControlAltDel
おそらく 'localhost'!==' localhost.example' –
のため、バージョン55のFirefoxでもhttpsの制限があります - firefoxで 'http:// localhostとfile://のようなローカルに配信されるファイルが考慮されます - それで、chrumと同じように動作します。 –