Can't access localStorage from global functions

I have a global function assigned to the window scope:

function testFunc() {
  console.log('test', window.localStorage)
}

and a query that calls it:

window.testFunc()

When the query is trigged I get this error:

query1: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.

Shouldn't global functions be able to access the localStorage?

Hi @vangelov :wave:

Sorry but I don't believe this is possible in Retool. Global functions in Retool mean that they are available in all your apps, but still can't reach outside of the JS sandbox.

We do however have an internal localStorage API that interacts with the browser's local storage. You can learn more about that here.

Hey @Pawan,

Thanks for your answer, but I think you misunderstood my question.

I'm adding my function in the Script and styles window:

These functions are assigned only to a single app, they are not available to other apps.

What I want to to is have a global function inside my app that sets a local storage key and be able to use it from different queries.

Something like this:

function setData(data) {
  localStorage.setValue('appData', data)
}

When I try this I get the above error, however.

Hi there :wave:

After some digging I'm able to confirm that this is a known bug/issue the team's aware of and currently isn't possible. The feature request however has been put in :crossed_fingers:

Best

Pawan

1 Like

A post was split to a new topic: Load local storage data on app open