Chrome.history.getVisits returning empty set, even though item exists in Chrome.history.search

丶灬走出姿态 提交于 2019-12-11 01:54:11

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/21243622/chrome-history-getvisits-returning-empty-set-even-though-item-exists-in-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!