Chrome Extension: How to print all bookmarks?

Hi guys, I’ve been struggling to figure out how to print out all the bookmarks when the user clicks the extension icon on the toolbar.
Finally, I figured it out after thousands of researching (with the help of Stackoverflow).

fina.PNGdocument.addEventListener executes getTree function when the HTML file is loaded.

Then I created a bmakr_arr array to store the titles of all the bookmark folders.
chrome.bookmarks.getTree function will call the printBookmakrs function which recursively iterates through the bookmarks.

In the printBookmarks function, what it does is, for each bookmark in the bookmarks, it will leave a log for each folder name. If you want to print the title of bookmarks inside the folder or those without the folder, you can do else{ console.log(bookmark.title).

function printArray is just there to print the elements of the array for the debugging purpose.

 

 

Leave a comment