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

bookmarks.getSubTree()

The bookmarks.getSubTree() method asynchronously retrieves a bookmarks.BookmarkTreeNode, given its ID.

If the item is a folder, you can access all its descendants recursively using its children property and the children property of its descendants, if they are themselves folders.

Syntax

chrome.bookmarks.getSubTree(
  id,                     // string
  function(               // function
    results                 // array of a single BookmarkTreeNode object
  ) {...}
)

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

Parameters

id
A string specifying the ID of the root of the subtree to retrieve.
callback
A function to call once the requested node has been retrieved. This function is passed the following parameters:
results
An array containing a single bookmarks.BookmarkTreeNode object, corresponding to the given ID.

Browser compatibility

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

Examples

This example recursively prints out the subtree under a given node:

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 logSubTree(bookmarkItems) {
  logItems(bookmarkItems[0], 0);
}

function handleClick() {
  var subTreeID = "unfiled_____";
  chrome.bookmarks.getSubTree(subTreeID, logSubTree);
}

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,