Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mohamedkhallouq
GitHub Repository: mohamedkhallouq/content
Path: blob/main/files/en-us/mozilla/add-ons/webextensions/api/bookmarks/gettree/index.md
6552 views
---
title: bookmarks.getTree() slug: Mozilla/Add-ons/WebExtensions/API/bookmarks/getTree page-type: webextension-api-function tags: - API - Add-ons - Bookmarks - Extensions - Method - Non-standard - Reference - WebExtensions - getTree browser-compat: webextensions.api.bookmarks.getTree
---

{{AddonSidebar()}}

bookmarks.getTree() returns an array containing the root of the bookmarks tree as a {{WebExtAPIRef("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()

Parameters

None.

Return value

A Promise that will be fulfilled with an array containing one object, a bookmarks.BookmarkTreeNode object representing the root node.

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);

{{WebExtExamples}}

Browser compatibility

{{Compat}}

Note: This API is based on Chromium's chrome.bookmarks API. This documentation is derived from bookmarks.json in the Chromium code.