Chrome.history.getVisits返回空集,即使项目存在于Chrome.history.search中 [英] Chrome.history.getVisits returning empty set, even though item exists in Chrome.history.search

查看:169
本文介绍了Chrome.history.getVisits返回空集,即使项目存在于Chrome.history.search中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想收集我以前的N个历史记录,然后查看我访问该页面的所有时间的时间戳记,只要我的历史记录包含该记录即可。

Chrome.history.search允许我获取最近N个历史记录的网址。然而,如果我现在在每个这些URL上调用Chrome.history.getVisits,那么即使它们存在于我的历史记录中,也会返回'[]'。此外,即使getVisits调用返回[],在chrome:// history中搜索URL也会正确返回项目。

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

下面显示API调用返回[],而历史记录正确显示结果。

解决方案

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

  function loadUrlVisits(url){var processVisitsWithUrl = function(url){//我们需要被访问的项目的url来处理访问。 //使用闭包将url绑定到回调的参数中。返回函数(visitItems){processVisits(url,visitItems); }; }; chrome.history.getVisits({url:url},processVisitsWithUrl(url));} function processVisits(url,visitItems){//处理访问项目...}  



可以从示例中找到参考扩展 here


I'd like to collect my past N history items, and then find the time stamp of all times I've visited that page going back as far as my chrome history contains.

Chrome.history.search allows me to get the urls of my last N history items.

However, if I now call Chrome.history.getVisits on each of those urls, some return '[]', even though they exist in my history. Furthermore, searching for the URL in chrome://history returns the item properly, even though the getVisits call returns [].

One further tidbit, this appears to be a problem the further back in my history I go. My first 50 items or so all return a proper [Object], but after that, nearly all (looks like 90%+) are empty sets [].

The image below shows the API call returning [], while the history correctly shows a result.

解决方案

By looking a the extension samples here, the fix is as follows. You need a closure to bind the url into the callback's args (the callback for chrome.history.getVisits() function) to make it work.

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...
}

The reference extension from the samples can be found here.

这篇关于Chrome.history.getVisits返回空集,即使项目存在于Chrome.history.search中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆