bookmarks.getRecent()
bookmarks.getRecent()
方法检索指定数量的最近添加的书签并返回一个 BookmarkTreeNode
对象数组。
这是一个返回 Promise
的异步函数。
语法
js
let gettingRecent = browser.bookmarks.getRecent(
numberOfItems, // 整型数
);
参数
numberOfItems
-
一个表示要返回的项目的上限的数字。返回的列表将最多包含此数量的最近添加的项目。此处允许的最小值是 1。如果传递 0 或更小的值,函数将抛出错误。
返回值
一个 Promise
,其会兑现一个 BookmarkTreeNode
对象数组。
示例
此示例记录最近添加的书签的 URL:
js
function onFulfilled(bookmarks) {
for (const bookmark of bookmarks) {
console.log(bookmark.url);
}
}
function onRejected(error) {
console.log(`错误:${error}`);
}
browser.bookmarks.getRecent(1).then(onFulfilled, onRejected);
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | ||||||
---|---|---|---|---|---|---|---|
getRecent |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
备注:
此 API 基于 Chromium 的 chrome.bookmarks
API。该文档衍生自 Chromium 代码中的 bookmarks.json
。