7

I am developing a website which require the use of the navigator.geolocation object through a local development environment on MACOSX. I am using Chrome 53. Considering geolocation is blocked on anything that isn't HTTPS how am I suppose to develop my website locally? The Google Developers site quotes:

Does this affect local development?

It should not, localhost has been declared as "potentially secure" in the spec and in our case geolocation requests served at the top level over localhost will still work.

Here's what I am seeing:

Geolocation console warnings

Any ideas? (aside from switch browser)

Gavin Kemp
  • 461
  • 6
  • 11
  • You can use `about://flags` instead of passing commanding arguments. Here is how to do it on Android's Google Chrome. – Sahil Singh Apr 02 '20 at 02:27

3 Answers3

9

http://localhost is treated as a secure origin, so you don't need to do anything, the Geolocation will work.

If you're using another hostname that points to the localhost (Ex: http://mysite.test) then you should run chrome from the command line with the following option: --unsafely-treat-insecure-origin-as-secure="http://mysite.test".

Example

google-chrome --unsafely-treat-insecure-origin-as-secure="http://yoursite.test"

More details on Deprecating Powerful Features on Insecure Origins

Kerkouch
  • 1,446
  • 10
  • 14
  • 5
    on my mac i didnt have the `google-chrome` symlink so instead i used `open -a /Applications/Google\ Chrome.app' --args --unsafely-treat-insecure-origin-as-secure="http://yoursite.test"` – stackPusher Jun 06 '18 at 03:05
0

Use file: protocol. Launch chrome with --allow-file-access-from-files flag set, see Jquery load() only working in firefox?. At Settings select Content settings, scroll to Location, select Ask when a site tries to track your physical location (recommended).

Community
  • 1
  • 1
guest271314
  • 1
  • 15
  • 104
  • 177
0

The answer to this question is to set VirtualHost in XAMPP to use the SSL Engine. This question has already been answered here: How do I use https (SSL) in XAMPP while using virtual hosts

This then allows the Geolocation to run through HTTPS on a local development environment using XAMPP.

Community
  • 1
  • 1
Gavin Kemp
  • 461
  • 6
  • 11