Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

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.

Syntax

chrome.bookmarks.getTree(
  function(                  // function
    results                    // array of a single BookmarkTreeNode object
  ) {...}
)

This API is also available as browser.bookmarks.getTree() in a version that returns a promise.

Parameters

callback
A function to be called once the root node has been obtained; it is passed the following parameters:
results
An array containing a single bookmarks.BookmarkTreeNode object, corresponding to the root node.

Browser compatibility

Chrome Edge Firefox Firefox for Android Opera
Basic support Yes No 45.0 No 33

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 handleClick() {
  chrome.bookmarks.getTree(logTree);
}

chrome.browserAction.onClicked.addListener(handleClick);

Acknowledgements

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

Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.

Document Tags and Contributors

 Contributors to this page: Makyen, wbamberg, Sheppy
 Last updated by: Makyen,