我正在尝试使用 chrome.history
删除我的扩展程序在后台窗口中自动访问的一些特定访问。
我发现至少有一个couple ways执行此操作:
chrome.history.deleteUrl(url)
:需要一个 URL 并删除所有出现的 URL。chrome.history.deleteRange(range)
:需要startTime
和endTime
并删除该范围内的所有网址。
如何将两者结合起来删除具有特定 URL 和时间范围的浏览器历史记录访问?
或者是否有另一种也许更好的方法来完全解决这个问题。例如,通过上述功能和 chrome.history.onVisited.addListener
的某种组合,主动设置监听器来删除 URL,同时自动浏览它们。 .
谢谢!
最佳答案
Chrome API 不提供按 URL 和日期删除历史记录项目的方法。您只能通过 chrome.history
访问历史记录或chrome. browsingData
并且两者都不具备以这种方式查询历史记录项目的能力。
我认为你最好的选择是使用 chrome.history.onVisited.addListener
就像你提到的方法。由于您的扩展程序正在访问网站,因此您知道要检查哪些网址。假设您只需要删除扩展程序运行时创建的历史记录项目,您可以使用类似...
chrome.history.onVisited.addListener((res) => {
if (res.url === 'someurl') {
const t = res.lastTimeVisisted;
// You might need to play with the end time
chrome.history.deleteRange({
startTime: t,
endTime: t
});
}
})
关于javascript - 如何根据 URL 和时间范围删除特定的浏览器历史记录项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61396210/