说明
使用 chrome.readingList
API 读取和修改阅读清单中的内容。
权限
readingList
如需使用 Reading List API,请在扩展程序清单文件中添加 "readingList"
权限:
manifest.json:
{ "name": "My reading list extension", ... "permissions": [ "readingList" ] }
可用性
Chrome 具有位于侧边栏中的阅读清单。它可让用户保存网页以供日后阅读或离线阅读。 使用 Reading List API 检索现有项,并向列表添加项或从中移除项。

概念和用法
商品排序
阅读清单中的项目不按任何保证的顺序排列。
商品的唯一性
商品按网址键控。包括哈希和查询字符串。
使用场景
以下部分展示了 Reading List API 的一些常见用例。如需查看完整的扩展程序示例,请参阅扩展程序示例。
添加项目
如需将内容添加到阅读清单,请使用 chrome.readingList.addEntry()
:
chrome.readingList.addEntry({ title: "New to the web platform in September | web.dev", url: "https://developer.chrome.com/", hasBeenRead: false });
展示商品
如需显示阅读清单中的内容,请使用 chrome.readingList.query()
方法检索这些内容。
const items = await chrome.readingList.query({}); for (const item of items) { // Do something do display the item }
将项目标记为已读
您可以使用 chrome.readingList.updateEntry()
更新标题、网址和阅读状态。以下代码将某项标记为已读:
chrome.readingList.updateEntry({ url: "https://developer.chrome.com/", hasBeenRead: true });
移除项目
如需移除某项内容,请使用 chrome.readingList.removeEntry()
:
chrome.readingList.removeEntry({ url: "https://developer.chrome.com/" });
扩展程序示例
如需查看更多 Reading List API 扩展演示,请参阅 Reading List API 示例。
类型
AddEntryOptions
属性
- hasBeenRead
布尔值
如果条目已被读取,则为
true
。 - title
字符串
条目的标题。
- 网址
字符串
相应条目的网址。
QueryInfo
属性
- hasBeenRead
布尔值(可选)
指示是搜索已读 (
true
) 还是未读 (false
) 项目。 - title
字符串(选填)
要搜索的影视内容。
- 网址
字符串(选填)
要搜索的网址。
ReadingListEntry
属性
- creationTime
数值
条目的创建时间。以自 1970 年 1 月 1 日以来的毫秒数记录。
- hasBeenRead
布尔值
如果条目已被读取,则为
true
。 - lastUpdateTime
数值
相应条目的上次更新时间。此值以自 1970 年 1 月 1 日以来的毫秒数表示。
- title
字符串
条目的标题。
- 网址
字符串
相应条目的网址。
RemoveOptions
属性
- 网址
字符串
要移除的网址。
UpdateEntryOptions
属性
- hasBeenRead
布尔值(可选)
更新后的已读状态。如果未提供值,则保留现有状态。
- title
字符串(选填)
新标题。如果未提供值,则保留现有功能块。
- 网址
字符串
要更新的网址。
方法
addEntry()
chrome.readingList.addEntry(
entry: AddEntryOptions,
): Promise<void>
如果阅读清单中不存在相应条目,则添加该条目。
参数
-
要添加到阅读清单中的条目。
返回
-
Promise<void>
query()
chrome.readingList.query(
info: QueryInfo,
): Promise<ReadingListEntry[]>
检索与 QueryInfo
属性匹配的所有条目。系统不会匹配未提供的属性。
参数
- 资讯
要搜索的媒体资源。
返回
-
Promise<ReadingListEntry[]>
removeEntry()
chrome.readingList.removeEntry(
info: RemoveOptions,
): Promise<void>
从阅读清单中移除条目(如果存在)。
参数
-
要从阅读清单中移除的条目。
返回
-
Promise<void>
updateEntry()
chrome.readingList.updateEntry(
info: UpdateEntryOptions,
): Promise<void>
更新阅读清单条目(如果存在)。
参数
-
要更新的条目。
返回
-
Promise<void>
事件
onEntryAdded
chrome.readingList.onEntryAdded.addListener(
callback: function,
)
当向阅读清单添加 ReadingListEntry
时触发。
参数
- callback
函数
callback
参数如下所示:(entry: ReadingListEntry) => void
onEntryRemoved
chrome.readingList.onEntryRemoved.addListener(
callback: function,
)
当从阅读清单中移除 ReadingListEntry
时触发。
参数
- callback
函数
callback
参数如下所示:(entry: ReadingListEntry) => void
onEntryUpdated
chrome.readingList.onEntryUpdated.addListener(
callback: function,
)
当阅读清单中的 ReadingListEntry
更新时触发。
参数
- callback
函数
callback
参数如下所示:(entry: ReadingListEntry) => void