【发布时间】:2014-05-27 02:39:31
【问题描述】:
每当我尝试使用 chrome.cookies.get() 函数从 cookie 中读取数据时,我都会收到此错误:
TypeError: Cannot read property 'get' of undefined.
我在我的 content.js 文件中调用该函数,它只会在 twitter.com 上运行(该部分有效)。
这是我的清单文件:
{
"manifest_version": 2,
"name": "Twitter-MultiSignin",
"description": "twiter sign in",
"version": "1.0",
"permissions": [ "cookies", "alarms" , "http://*/*", "https://*/*", "storage"],
"content_scripts": [{
"matches": ["http://twitter.com/*","https://twitter.com/*"],
"js": ["jquery.js","content.js"]
}],
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
}
}
这是我的 content.js(它总是在 twitter 页面上发出警报,因此可以正常工作):
$(function() {
alert('got here');
try{
chrome.cookies.get({ url: 'https://twitter.com', name: 'auth_token' }, function (cookie){
alert(cookie.value);
});
}catch(err){
//do nothing
alert(err);
}
try{
chrome.cookies.get({ url: 'https://twitter.com', name: 'twid' },
function (cookie) {
if (cookie) {
twid_raw = cookie.value;
twid = twid_raw.split('=')[1]
alert(twid);
}
else{
alert("not found");
}
});
}catch(err){
//do nothing
}
})
【问题讨论】:
标签: google-chrome google-chrome-extension content-script