2014-01-20 20 views
2

我想收集我以前的N个历史记录项,然后找到我访问该页的所有时间的时间戳记回到我的铬历史包含。Chrome.history.get返回空集,即使项目存在于Chrome.history.search中

Chrome.history.search允许我获取最近N个历史项目的网址。

但是,如果我现在在每个这些URL上调用Chrome.history.getVisits,有些将返回'[]',即使它们存在于我的历史记录中。此外,即使getVisits调用返回[],在chrome:// history中搜索URL也会正确返回项目。

还有一个消息,在我的历史中,这似乎是一个问题。我的前50项左右都返回了一个合适的[Object],但在此之后,几乎所有(看起来像90%+)都是空集[]。

下图显示了API调用返回[],而历史记录正确显示了结果。 enter image description here

回答

0

通过查看扩展示例here,修复如下。您需要一个闭包来将url绑定到回调的参数(chrome.history.getVisits()函数的回调)中以使其工作。

function loadUrlVisits(url){ 
 
    var processVisitsWithUrl = function(url) { 
 
    // We need the url of the visited item to process the visit. 
 
    // Use a closure to bind the url into the callback's args. 
 
     return function(visitItems) { 
 
      processVisits(url, visitItems); 
 
     }; 
 
    }; 
 
    chrome.history.getVisits({url: url}, processVisitsWithUrl(url)); 
 

 
} 
 

 
function processVisits(url, visitItems){ 
 
    //process visit items here... 
 
}

从样品的参考扩展可以发现here

相关问题