每当我尝试使用该chrome.cookies.get()函数从cookie中读取时,我都会收到此错误:
TypeError: Cannot read property 'get' of undefined.
Run Code Online (Sandbox Code Playgroud)
我在我的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"
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的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) { …Run Code Online (Sandbox Code Playgroud) 我正在创建Google Chrome扩展程序(我的第一个扩展程序),并且我希望将扩展程序中的邮件发送到当前选项卡.
我正在关注文档:
https://developer.chrome.com/apps/runtime#event-onMessage
该扩展将一个小的外部JS加载到选项卡的HTML中,该HTML包含以下代码:
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
console.log(request)
}
);
Run Code Online (Sandbox Code Playgroud)
加载JS后,我收到以下错误:
Uncaught TypeError: Cannot read property 'onMessage' of undefined.
打开控制台和键入chrome,我可以看到运行时不是属性chrome.
看起来我做错了什么,但是什么?我需要在manifest.json文件中添加内容吗?
Chrome版本39.0.2171.71米
谢谢.