[英]Getting this error "await is only valid in async functions and the top level bodies of modules" in chrome extension with async await
I can't understand why this is throwing that error when I am working inside async await functions... Not sure if makes a difference but I am executing this code inside the content script of a chrome extension我不明白为什么当我在 async await 函数中工作时会抛出该错误...不确定是否有所不同但我在 chrome 扩展的内容脚本中执行此代码
Thanks in advance!提前致谢!
const getFromStorage = async function(key) {
return new Promise((resolve, reject) => {
chrome.storage.sync.get(key, resolve);
})
.then(result => {
if (key == null) return result;
else return result[key];
});
}
let updateArray = await getFromStorage("toSaveArray");
Top level await is not yet supported尚不支持顶级等待
You probably have to use an an Anonymous Function, for example:您可能必须使用匿名电话 Function,例如:
(async () => {
let updateArray = await getFromStorage("toSaveArray");
})();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.