由于缺少 HTTPS,HTML5 位置 API 在 VM 中不起作用?
HTML5 location API doesn't work in VM due to lack of HTTPS?
我正在 Vagrant VM "local-ish" 服务器上开发并通过主机上的 Chromium 进行测试。
在我的脚本中,我使用 HTML5 的位置 API 将数据发送到我的 VM 服务器。当我 运行 我的应用程序使用 Chromium 时,它按预期工作,即使它警告我:
getCurrentPosition() and watchPosition() are deprecated on insecure
origins, and support will be removed in the future. 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.
虽然,当我使用 Chrome (DEV) 测试 Android 时,我的代码在调用 navigator.geolocation.getCurrentPosition(callback)
时挂起。
当我使用 Chromium 的远程调试功能检查我的设备时,弹出相同的警告。
所以我有两个问题:
- 无论如何我可以在我的 VM 上 "fake" https 吗?
- 如果没有,我该如何规避这个问题,以便我可以在 Android 中测试我的应用程序?
为什么要造假?只需使用 Let's Encrypt 为您拥有的域生成证书。这样您将测试一个真实的配置。
因此,在阅读了一段时间后,我找到了解决问题的方法。我 +1 @Tom 的回答是因为它在其他情况下有意义,但在我的情况下不是特别的,因为我没有域并且我的应用程序没有投入生产,它只是为了学习目的。
我基本上是跟着一个Digital Ocean tutorial on own to create a self-signed certificate, but instead of using it directly with Nginx, I used it with npm's https
module, similar to what I found in this SO question.
这样,我 运行 在我的 vagrant VM 上的服务器正在处理 HTTPS 请求,Chromium 不会因为上面的警告而让我烦恼,也不会阻止位置数据进入我的 VM 服务器,这就是我想要实现的目标。
我正在 Vagrant VM "local-ish" 服务器上开发并通过主机上的 Chromium 进行测试。
在我的脚本中,我使用 HTML5 的位置 API 将数据发送到我的 VM 服务器。当我 运行 我的应用程序使用 Chromium 时,它按预期工作,即使它警告我:
getCurrentPosition() and watchPosition() are deprecated on insecure origins, and support will be removed in the future. 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.
虽然,当我使用 Chrome (DEV) 测试 Android 时,我的代码在调用 navigator.geolocation.getCurrentPosition(callback)
时挂起。
当我使用 Chromium 的远程调试功能检查我的设备时,弹出相同的警告。
所以我有两个问题:
- 无论如何我可以在我的 VM 上 "fake" https 吗?
- 如果没有,我该如何规避这个问题,以便我可以在 Android 中测试我的应用程序?
为什么要造假?只需使用 Let's Encrypt 为您拥有的域生成证书。这样您将测试一个真实的配置。
因此,在阅读了一段时间后,我找到了解决问题的方法。我 +1 @Tom 的回答是因为它在其他情况下有意义,但在我的情况下不是特别的,因为我没有域并且我的应用程序没有投入生产,它只是为了学习目的。
我基本上是跟着一个Digital Ocean tutorial on own to create a self-signed certificate, but instead of using it directly with Nginx, I used it with npm's https
module, similar to what I found in this SO question.
这样,我 运行 在我的 vagrant VM 上的服务器正在处理 HTTPS 请求,Chromium 不会因为上面的警告而让我烦恼,也不会阻止位置数据进入我的 VM 服务器,这就是我想要实现的目标。