Chrome扩展:Can't从chrome.local变量中检索值
Chrome Extension: Can't retrieve values from chrome.local variables
我正在pop.js
中设置chrome.local
变量,但无法在content.js
中检索它们
popup.js
chrome.storage.local.set('TITLE',title);
content.js
var title = null;
$(".class").each(function () {
chrome.storage.local.get('TITLE', function (result) {
title = result.TITLE;
console.log('inside'+title);//prints value
});
}
console.log(title);//returns null;
返回title
作为null
Chrome控制台输出为:
outside: null
content.js:42 insideJava: A Beginner's Guide, Sixth Edition
chrome.storage.local.get
是一个异步调用,这意味着当您调用console.log(title);
时,chrome.storage.local.get
的回调尚未执行,那么title
仍然是null
。你应该把你的逻辑放在回调中。
相关文章:
- 模拟chrome.storage.local函数使用Jasmine
- Chrome扩展:Can't从chrome.local变量中检索值
- chrome.storage.local.get 如何设置值
- chrome.storage.local["mykey"] is undefined
- 从chrome.storage.local获取基元值
- chrome.storage.local.set using a variable key name
- 将客户端生成的密码短语存储在chrome.storage.local中的安全含义
- Google Chrome Apps: chrome.storage.local
- Chrome.storage.local获取错误值
- Chrome.storage.local不能访问其他脚本中的数据
- chrome.storage.local.get结果为“未定义”;当调用
- 访问chrome.storage.local的问题.从options.html中设置/获取
- window.localStorage vs chrome.storage.local
- 使用chrome.storage.local.get获取一个值并将其赋值给一个变量
- 如何清除chrome.storage.local和chrome.storage.sync
- 如何使用chrome.storage.local.get和XMLHttpRequest同步执行一个函数
- rewriting localStorage javascript for chrome.local.set
- Chrome.Storage.Local Persistence
- 角度承诺然后回调不会在chrome.storage.local.get上触发
- 如何更新chrome.storage.local键和值