A Geolocation request can only be fulfilled in a secure context
Asked Answered
S

2

5

I am using HTML5 Geolocation feature. My code is well running in 'localhost' but problem in 'subdomain' .My code below:

 if (navigator.geolocation) {
                navigator.geolocation.getCurrentPosition(showPosition, showError);
  } else {
         console.log("Geolocation is not supported by this browser.");
   }
Schonthal answered 18/4, 2018 at 10:8 Comment(2)
you need to secure your domain with an SSL certificate and call your code with an https url like vom.local.comOzan
Actually the problem is mentioned in the error message. A Geolocation request can only be fulfilled in a secure context.. Please check the following answers: #37193327 and the following one: #37836305Charmainecharmane
I
14

In most cases, localhost will be treated as a secure URL regardless of HTTP or HTTPS connection. This is to ease the development process and allow you to make use of features that would only be accessible through a secure connection.

However, if you are still having issues with this on localhost or want to access the website remotely via HTTP with geolocation enabled, the following steps should set you up:

  1. Download chrome and paste the following URL into your address bar chrome://flags/#unsafely-treat-insecure-origin-as-secure.

  2. On that page locate the Insecure origins treated as secure flag and add the URL which is failing to load the geolocation in the text box. e.g. example.com or localhost in your case.

  3. Once you've added it, select enable on the right-hand side.

  4. Click the reload changes button and then revisit the website, it should now ask for geolocation.

Inquiry answered 25/4, 2019 at 22:31 Comment(3)
any way to do this on firefox?Moonraker
Yes please let us know about firefox alsoRigging
Actually someone has posted a similar doubt for firefox also. However according to the answers given to that question, sadly there is no such feature in firefox. An open bug had been filed for the same. Please refer: #66678623Rigging
T
-1

Set the HTTPS environment variable to true, then start the dev server as usual with npm start: if your on Unix just do this HTTPS=true npm start Note that the server will use a self-signed certificate, web browser will stop connecting to the site and will show you an error page with the message, Warning: Potential Security Risk Ahead. I hope this helps happy coding :)

Tutelage answered 22/7, 2019 at 17:17 Comment(1)
Why assume the OP is running Nodejs?Orellana

© 2022 - 2024 — McMap. All rights reserved.