Navigator.geolocation does not have permissions in a javascript query

Simply, trying to access navigator.geolocation.getCurrentPosition in a javascript query does not work. Create a javascript query with a simple construction:

if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition((position) => { console.log('hello')}, (error) => { console.error(error); });
}

We expect a browser prompt to access the current location. It never appears, instead calling the error function immediately. Running the query errors depending on the browser. Chrome states

Geolocation has been disabled in this document by permissions policy

Firefox states

User denied geolocation prompt

(Which isn't true, the prompt never appears).

However, while in the javascript browser console, calling navigator.geolocation.getCurrentPosition works fine. The prompt for retool.com to access the current location appears, and the success callback works with the coordinates.

Hey Rory,

I don't believe this is possible as Retool sandboxes queries on runtime. I'm not familiar with the inner workings of this but it's generally difficult (impossible) to access parent functions from within a Retool query.

Anyone, please correct me if I'm wrong :stuck_out_tongue:

That may be true. I just tried it as an application javascript snippet, still the same error. It seems like there's something outside my control specifically setting it to always deny.

Hey @Rory!

Retool does run sandboxed JavaScript as @minijohn mentioned which adds some restrictions. It is possible to access the user's geolocation in certain places though.

  • Otherwise, you can try defining a global variable that holds the user's geolocation using preloaded JavaScript:

Let me know if either of those work!

1 Like