如何使用chrome.history API获取最近访问过的标签页的网址,特别是访问过的最后10个网址?
答案 0 :(得分:21)
将空字符串作为查询传递给search() method of the chrome.history API。例如,这会将最近访问的10个URL记录到控制台:
chrome.history.search({text: '', maxResults: 10}, function(data) {
data.forEach(function(page) {
console.log(page.url);
});
});
答案 1 :(得分:0)
您必须输入:
"permissions": [
"history"
],
在扩展名的manifest.json文件中,然后您的代码应如下所示:
chrome.history.search({
'text': '', // Return every history item....
'startTime': oneWeekAgo, // that was accessed less than one week ago.
'maxResults': 100 // Optionally state a limit
},
function(historyItems) {
// For each history item, get details on all visits.
for (var i = 0; i < historyItems.length; ++i) {
var url = historyItems[i].url;
// do whatever you want with this visited url
}
}