Manav
Manav

Reputation: 306

How to solve Only secure origins are allowed

I am using cordova geolocation plugin in Ionic app . when i ran the app inside emulator i found this bug Only secure origins are allowed . hence was unable to get the geolocation of inside emulator . but using locahost it works fine probably localhost comes under secure origin.

browser im using is chrome. plugin https://ionicframework.com/docs/native/geolocation/

Upvotes: 5

Views: 20704

Answers (4)

Afril
Afril

Reputation: 1

In my case, I am using NuxtJS(Vue2). I use http://192.168.50.48:3000 as a host. Instead of using this, I build with http://localhost:3000. It works just fine now. Switching it back to localhost, and it starts to work.

Upvotes: 0

Jakasha
Jakasha

Reputation: 21

The problem is that the default web view scheme for Android is: http://localhost The geolocation plugin does not accept "http://..." as origin for position requests. On iOS it works because the default scheme is ionic://localhost

Set the Android Scheme to "https" in the config.xml file:

<preference name="Scheme" value="https" />

NB: it is necessary to allow also the navigation for the new scheme:

<allow-navigation href="https://*"/>

Other web view configurations: https://github.com/ionic-team/cordova-plugin-ionic-webview

Upvotes: 1

rafaelnaskar
rafaelnaskar

Reputation: 783

For private IP address access, the latest Firefox seems to work out of the box (version 47.0 and above). If it does not work, go to about:config and set the media.navigator.permission.disabled to false. It's work for android too.

Upvotes: 0

danilonet
danilonet

Reputation: 1795

there is an issue opened for this problem https://github.com/ionic-team/ng-cordova/issues/1413

Accessing the user's location is deprecated with unsecure (HTTP) context. See https://www.chromium.org/Home/chromium-security/prefer-secure-origins-for-powerful-new-features.

Running your dev server on localhost instead should work.

Upvotes: 4

Related Questions