如何使用chrome.history API获取最近访问标签页的URL,特别是最近访问的10个URL?
如何使用chrome.history API获取最近访问标签页的URL,特别是最近访问的10个URL?
chrome.history.search({text: '', maxResults: 10}, function(data) {
data.forEach(function(page) {
console.log(page.url);
});
});
您需要添加:
"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
}
}