If I try the following code:
chrome.bookmarks.getTree(function(items) {
items.forEach(function(item) {
document.write(item.url);
});
});
it returns undifined. But when I write:
chrome.bookmarks.getRecent(20, function(items) {
items.forEach(function(item) {
document.write(item.url);
});
});
it works.
Why does it differ?
Both
chrome.bookmarks.getTreeandchrome.bookmarks.getRecentreturn an array of BookmarkTreeNodes, but BookmarkTreeNodes do not necessarily have aurlproperty. In the case ofgetTree, the top nodes of the tree are folders and do not have URLs:If you use
getTree, you’ll have to traverse the tree recursively using each node’schildrenarray. It helps to know that every BookmarkTreeNode either has achildrenattribute (if it’s a folder) or aurlattribute (if it’s an actual bookmark). Try something like: