history

使用 history API 与浏览器历史记录进行交互。

如果您正在查找关于浏览器会话历史记录的信息,请参阅 History 接口

注意: 下载被视为 HistoryItem 对象。因此,诸如 history.onVisited 等事件会为下载触发。

浏览器历史记录是用户访问过的页面的按时间顺序排列的记录。history API 使您能够

但是,用户可能多次访问过同一页面,因此该 API 还包含了“访问”的概念。所以您也可以使用此 API 来

要使用此 API,扩展必须在其 manifest.json 文件中请求 "history" 权限

类型

history.TransitionType

描述了浏览器如何导航到某个特定页面。

history.HistoryItem

提供有关浏览器历史记录中某个特定页面的信息。

history.VisitItem

描述对某个页面的单次访问。

函数

history.search()

在浏览器历史记录中搜索与给定条件匹配的 history.HistoryItem 对象。

history.getVisits()

检索关于给定页面访问的信息。

history.addUrl()

将对给定页面的访问记录添加到浏览器历史记录中。

history.deleteUrl()

从浏览器历史记录中删除对给定 URL 的所有访问。

history.deleteRange()

删除用户在给定时间范围内访问过的所有页面的访问记录。

history.deleteAll()

从浏览器历史记录中删除所有访问记录。

事件

history.onTitleChanged

当用户访问的页面的标题被记录时触发。

history.onVisited

每次用户访问页面时触发,提供该页面的 history.HistoryItem 数据。

history.onVisitRemoved

当 URL 被完全从浏览器历史记录中删除时触发。

扩展程序示例

浏览器兼容性

注意: 此 API 基于 Chromium 的 chrome.history API。本文档源自 Chromium 代码中的 history.json