bookmarks.getTree()
bookmarks.getTree()
returns an array containing the root of the bookmarks tree as a bookmarks.BookmarkTreeNode
object.
You can access the entire tree recursively using its children
property and the children
property of its descendants, if they are themselves folders.
This is an asynchronous function that returns a Promise
.
Syntax
let gettingTree = browser.bookmarks.getTree()
Examples
This example prints out the entire bookmarks tree:
function makeIndent(indentLength) {
return ".".repeat(indentLength);
}
function logItems(bookmarkItem, indent) {
if (bookmarkItem.url) {
console.log(makeIndent(indent) + bookmarkItem.url);
} else {
console.log(`${makeIndent(indent)}Folder`);
indent++;
}
if (bookmarkItem.children) {
for (child of bookmarkItem.children) {
logItems(child, indent);
}
}
indent--;
}
function logTree(bookmarkItems) {
logItems(bookmarkItems[0], 0);
}
function onRejected(error) {
console.log(`An error: ${error}`);
}
let gettingTree = browser.bookmarks.getTree();
gettingTree.then(logTree, onRejected);
Browser compatibility
|
Desktop |
Mobile |
|
Chrome |
Edge |
Firefox |
Internet Explorer |
Opera |
Safari |
WebView Android |
Chrome Android |
Firefox for Android |
Opera Android |
Safari on IOS |
Samsung Internet |
getTree |
Yes |
15 |
45 |
? |
Yes |
No |
? |
? |
No |
? |
No |
? |