我想在用户访问faceboook网址时进行记录,但在使用onVisited时出现错误 这是我的background.js
chrome.history.onVisited.addListener(function(historyItem){
if(historyItem.url === "https://www.facebook.com/"){
console.log('user visits '+historyItem.url+ ' at '+historyItem.lastVisitTime+ ' number of times visited '+historyItem.visitCount);
}
});
我还在manifest.json中添加了权限:
{
"manifest_version": 2,
"name": "My Proj Extension",
"version": "0.1",
"background":{
"scripts":["background.js"],
"permissions": ["tabs", "history"]
},
"content_scripts":[
{
"matches": ["<all_urls>"],
"js": ["content.js"]
}
]
}
任何人都可以建议为什么这不起作用,我怎么能这样做..
答案 0 :(得分:0)
权限密钥不应位于后台:
{
"manifest_version": 2,
"name": "My Proj Extension",
"version": "0.1",
"permissions": ["tabs", "history"],
"background":{
"scripts":["background.js"],
},
"content_scripts":[
{
"matches": ["<all_urls>"],
"js": ["content.js"]
}
]
}