确保所有必要的权限。 storage
,就你的情况而言。
Make sure that all necessary permissions have been declared in the manifest file. "storage"
, in your case.
一般来说,以下步骤应该可以解决Chrome显然未定义的问题API:
In general, the following steps should fix the problem of apparently undefined Chrome APIs:
- 阅读您正在使用的API的文档,并熟悉先决条件,通常是清单权限( eg
chrome.storage
#manifest ) 。 通过查看新增功能。
- 检查脚本是否正确运行上下文。大多数API仅适用于扩展程序的过程。 (
chrome.storage
API也可以在内容脚本中使用)
- 否则,请使用常用的调试技巧:错别字,变量阴影......
- Read the documentation of the API you're using and get yourself familiar with the prerequisites, usually manifest permissions (e.g.
chrome.storage
#manifest).
- Check if your (user's) Chrome version supports the API, by looking at What's new.
- Check if the script is running in the right context. Most APIs are only available to the extension's process. (the
chrome.storage
API can also be used in content script though)
- Otherwise, resort to your usual debugging skills: Typos, variable shadowing, ...