Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access to storage is not allowed from this context. #19

Open
andreademasi opened this issue Nov 10, 2022 · 2 comments
Open

Access to storage is not allowed from this context. #19

andreademasi opened this issue Nov 10, 2022 · 2 comments

Comments

@andreademasi
Copy link

Trying to use storage.get() in a content script results in Access to storage is not allowed from this context.
Here's my code:

// content.ts

const storage = new Storage({ area: "session" })

const init = async () => {
  value = await storage.get("key")
}

init()

I can't call storage.get() outside an async function so am I doing something wrong?

@ColdSauce
Copy link
Contributor

The session area is relatively new (introduced in Chrome 102). I suspect some unique property of session-type storage causes this.

@ahallaha
Copy link

ahallaha commented Dec 7, 2023

From the docs

By default, it's not exposed to content scripts, but this behavior can be changed by setting chrome.storage.session.setAccessLevel().

setAccessLevel isn't supported in Plasmo so you need to call it from the browser storage api.

// background.ts

(async () => {
  const storage = new Storage({ area: "session" })
  const extStorageApi = storage.getExtStorageApi()
  await extStorageApi.session.setAccessLevel({ accessLevel: "TRUSTED_AND_UNTRUSTED_CONTEXTS" })
})()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants