chrome.storage is undefined in chrome extension
Asked Answered
G

2

12

I'm developing a Google Chrome extension, and have been working on one for a while. So it's been installed for a while, and I updated the manifest file to include the "storage" permission and reloaded the extension. However, when I try it in the console, chrome.storage is undefined. I restarted Chrome and still nothing.

My manifest file looks like this:

{
    ... snip ...
    "permissions": [
        "tabs",
        "http://*/*",
        "https://*/*",
        "chrome://favicon/",
        "storage"
    ]
}

I could reinstall the application, but I'm hesitant, since: Will it be the same for the existing users of the extension? It says in the documentation that the permission won't show any warnings or temporarily block the extension for adding more permissions.

My question is mainly, how will the existing users of my extension be affected? Will they get a warning and have the extension disabled until they actively enable it? Or is it just a local develpment issue?

Gamone answered 10/9, 2012 at 16:58 Comment(1)
How exactly are you trying it in the console? Should it not be undefined until you actually use it?Hutchings
H
11

Your manifest looks fine. Did you reload your extension after making the change?

I pasted your manifest permissions into a new extension and called:

console.log(chrome.storage);

And recieved the following:

chrome.storage output

Note "local" and "sync", the two types of storage available to the extension.

Hirz answered 18/10, 2012 at 20:44 Comment(2)
I had to completely remove and re-install my extension. Clicking reload did not work.Thunderstruck
@Thunderstruck can confirm, same problem/solution.Ayeshaayin
F
0

In the case you are adding new permissions to the manifest file manually, I see that to make the new manifest file work, you'd have to remove and add it back again.

Some background if it's helpful: I'm migrating a manifest-v2 to manifest-v3, with a new framework called "plasmo".

  1. The permission from plasmo generated manifest v3 is not working (seems plasmo haven't implemented it yet).
  2. To do it safely, I used Overriding the Manifest to create a storage permission.
  3. Only reloading the extension won't grant the new permissions to the extension. You need to remove the extension and add it again.
Fracas answered 25/5, 2024 at 0:5 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.