[英]SyntaxError: await is only valid in async functions and the top level bodies of modules
[英]Getting this error "await is only valid in async functions and the top level bodies of modules" in chrome extension with async await
我不明白為什么當我在 async await 函數中工作時會拋出該錯誤...不確定是否有所不同但我在 chrome 擴展的內容腳本中執行此代碼
提前致謝!
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");
尚不支持頂級等待
您可能必須使用匿名電話 Function,例如:
(async () => {
let updateArray = await getFromStorage("toSaveArray");
})();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.