首页 > 解决方案 > chrome.history.search() 不会返回所有历史记录

问题描述

所以在过去的几周里,我一直在尝试让自己成为一个自动删除历史的 chrome 扩展,我以为我快完成了,但后来我意识到 chrome.history.search() 并没有返回所有的历史,只有一些,我无法弄清楚为什么某些历史记录会被删除,而有些则不会。我目前有

`chrome.storage.sync.get({ // Retrieving the stored array of words
    list: []
},
function(data) {
    for (i = 0; i < data.list.length; i++) {
        let searchString = data.list[i].toString(); //String that is searched for
        chrome.history.search({ // History search function
          text: searchString, // String to search for
          startTime: 2678400000,
          maxResults: 5000,
      }, checkHistory)
  }
});`

我的回调函数是

`function checkHistory(historyItems) {
    for (let item of historyItems) { // Deleting items that were found in the search
        chrome.history.deleteUrl({
            url: item.url
        });
    }
}`

我的目标是,例如,如果我搜索“Google”,它将删除所有带有子字符串“Google”的搜索。我 100% 确定该列表不是问题,因为它打印得很好,我注意到的一件事是,当我尝试删除时,它总是会删除所有超过 2-3 天的子字符串,我以为我会把它放在那里我不确定这是否意味着什么。我将不胜感激任何有关问题可能的见解。谢谢!

标签: javascriptgoogle-chromebrowser-history

解决方案


也许是因为开始时间,找到chrome如何计算它的时间。如果它不起作用,请尝试 API

chrome.history.deleteRange(object range, function callback)

推荐阅读