2011-11-23 147 views
1

我是一个新手而且相当初学,但我试图编写一个扩展,它需要在chrome的历史记录中搜索一个url。我一直在寻找的在这里的代码和谷歌,但仍然未能零件...chrome.history.search() - > undefined [chrome扩展名]

我的表现似乎是正确的:

"permissions" : [ 
    "tabs", 
    "history" 
    ], 

但JavaScript部分较为混乱:

var histories = []; 

chrome.history.search({text:'', maxResults:0, startTime: 0}, function(historyItems){ 
for(var h in historyItems){ 
    histories.push({'id':h.id, 'url':h.url}); 
    } 
}); 
console.log(histories.length + ' histories'); 

alert(histories.length); 

警报显示0.异步问题在这里不应该是一个问题。 谢谢你的帮助。

回答

0

您有maxResults设置为0,因此不会返回任何结果。

尝试将整数maxResults设置为正整数,如100或完全忽略maxResults以返回所有匹配的历史记录项目。

您还想要移动alert()console.log()功能是chrome.history.search的回调函数中,否则histories.length0当函数被调用。

+0

谢谢,但看起来h.url是未定义的,但它可以工作,否则 –

+0

啊,将'h.id'更改为'historyItems [h] .id'和'h.url'为'historyItems [h]。网址:) –