chrome.storage is undefined in chrome extension

2019-04-06 14:09发布

问题:

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?

回答1:

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:

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