javascript 如何在 Chrome 扩展程序中使用历史 API 获取浏览历史

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24894627/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 03:31:29  来源:igfitidea点击:

How to get browsing history using history API in Chrome extension

javascriptgoogle-chromegoogle-chrome-extensionbrowser-history

提问by aayushsarva

How can I get the URLs of recently visited tabs using chrome.history API, specifically, the last 10 URLs visited?

如何使用 chrome.history API 获取最近访问过的选项卡的 URL,特别是最近访问的 10 个 URL?

回答by Chris

Pass an empty string as your query to the search() method of the chrome.history API. For example, this will log the 10 most recently visited URLs to the console:

将空字符串作为查询传递给chrome.history APIsearch() 方法。例如,这会将最近访问的 10 个 URL 记录到控制台:

chrome.history.search({text: '', maxResults: 10}, function(data) {
    data.forEach(function(page) {
        console.log(page.url);
    });
});