ERROR (1): User denied Geolocation


Apparently the problem is because Chrome blocks the user's location queries that are not safe, so I posted a question in Meta SE.

In stack snippet I am testing the code of link

When I run it, the stack snippet console shows me


Warning: ERROR (1): User denied Geolocation

In my browser settings I have given permission to show my location to What more do I need?

var options = {
  enableHighAccuracy: true,
  timeout: 5000,
  maximumAge: 0

function success(pos) {
  var crd = pos.coords;

  console.log('Your current position is:');
  console.log('Latitude : ' + crd.latitude);
  console.log('Longitude: ' + crd.longitude);
  console.log('More or less ' + crd.accuracy + ' meters.');

function error(err) {
  console.warn('ERROR(' + err.code + '): ' + err.message);

navigator.geolocation.getCurrentPosition(success, error, options);
asked by Rubén 24.06.2017 в 20:41

1 answer


The stack snippets run in a sandbox , so they do not have permission to obtain the location, and there is no option that the user can enable to allow it.

Specifically, it is because Stack Overflow does not configure the flag allow-same-origin . That is, that

  • what in your publication is like:

    <iframe name="833b0476-911f-9afa-831a-c6f045c3a074" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit" frameborder="0"></iframe>
  • it should be this way so that the location can be obtained:

    <iframe name="833b0476-911f-9afa-831a-c6f045c3a074" sandbox="allow-same-origin allow-forms allow-modals allow-scripts" class="snippet-box-edit" frameborder="0"></iframe>
    <!--                                                         ⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️                                                                                        -->

If it is added or not, it is a complex discussion for MSE , which has already been consulted on occasion. Meanwhile, it's like this by design .


  • Publish the code in JSFiddle and add the link in your post.
  • Ask the user to run this on the console before running the snippet:

    for (let snippet of document.querySelectorAll('iframe.snippet-box-edit')) { snippet.sandbox.add('allow-same-origin') }
  • answered by 25.06.2017 / 04:55