在我的代码中,我希望使用来自其发布到的网站(meepcity.com)的cookie发布到两个php文件。但是,在加载chrome扩展时,我收到以下两个错误:
Error in response to cookies.get: TypeError: Cannot read property 'value' of undefined at token
以及
Unchecked runtime.lastError while running cookies.get: No host permissions for cookies at url: "http://www.meepcity/". at token
我没有看到我的代码有任何问题,但我认为问题与检索cookie有关。我已经包含了我的代码以及下面的清单。谢谢!
function token(domain, name, callback) {
chrome.cookies.get({"url": domain, "name": name}, function(cookie) {
if(callback) {
callback(cookie.value);
}
});
}
token("http://www.meepcity", "PHPSESSID", function(secureToken) {
function buy(id, security) {
$.ajax({url:"http://api.meepcity.com/prepareAssetPurchase.php",type:"POST",data:{sess:security,aId:id,sId:0}})
$.ajax({url:"https://api.meepcity.com/finishAssetPurchase.php",type:"POST",data:{sess:security}}).done(function() { console.info("Successfully purchased!"); });
}
buy(44,secureToken);
});
清单
{
"background": {
"scripts": [ "jquery.js", "background.js" ]
},
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
"description": "Meepcity",
"homepage_url": "http://www.meepcity.com/",
"incognito": "split",
"manifest_version": 2,
"name": "Meepcity",
"permissions": [ "unlimitedStorage", "tabs", "notifications", "tabCapture", "*://*.meepcity.com/*", "https://*.meepcity.com/*", "cookies", "background" ],
"short_name": "Meepcity",
"update_url": "https://clients2.google.com/service/update2/crx",
"version": "1.0.1",
"web_accessible_resources": [ "*://*.meepcity.com/*", "https://*.meepcity.com/*" ]
}
谢谢,我很感激。
答案 0 :(得分:1)
不确定,但我认为你应该这样做:
希望它有效