我正在尝试构建Chrome扩展程序,并希望能够从我的历史记录中删除某些网站。例如,我尝试从浏览历史记录中删除对YouTube的所有引用。扩展不会在弹出控制台中抛出任何错误或警告。问题是,在“删除”项目后,它们仍会显示在我的历史记录中。
无论如何这里是代码
清单文件
"manifest_version": 2,
"name": "Eraser",
"description": "This extension will delete history",
"version": "1.0",
"content_security_policy": "script-src 'self' https://ajax.googleapis.com; object-src 'self'",
"permissions": [
"history",
"browsingData"
],
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html",
"default_title": "Erase"
}
的Javascript
function erase(){
var now = new Date();
var milleSecondsInAYear = 31536000000;
var oneYearAgo = now.getTime() - milleSecondsInAYear;
chrome.history.search({"text":"Youtube", "startTime":oneYearAgo, "maxResults":1000000},
function(history){
for(var i = 0; i < history.length; i++){
chrome.history.deleteUrl({"url":history[i].url});
}
$("#result").html( $("#result").html() + history.length + " items have been removed");
});
}