3

I read the MDN documentation about how to get a reference to the bookmarks tree und to navigate within. But how do I know which folder represents the bookmarks toolbar? This toolbar is named differently depending on the locale. I am not sure whether a user is still allowed to select an arbitrary folder for this, but this was possible some years ago.

I found this post: Programmatically bookmark pages in bookmark toolbar using firefox extension

but this is not about the new webextension API that everybody has to use now.

Flexo
  • 87,323
  • 22
  • 191
  • 272
dsfsdfdsf
  • 41
  • 2
  • 1
    You can use this browser.bookmarks.get("toolbar_____").then((value) => { console.log(JSON.stringify(value)); }, null); – Smile4ever Dec 17 '18 at 11:31
  • 1
    Please note that the bookmark ID "toolbar_____" is not guaranteed to be stable, but you can probably keep using this for now. – evilpie Dec 17 '18 at 15:57

1 Answers1

1

As per comments, there are special IDs you can search for.

// If you just need the node or its contents
let toolbar_node = await browser.bookmarks.get("toolbar_____");
let toolbar_subtree = await browser.bookmarks.getSubTree("toolbar_____");

// If you're walking the tree on your own
if (node.id == "toolbar_____") { /* it's the toolbar */ }

They were apparently introduced in https://bugzilla.mozilla.org/show_bug.cgi?id=1071505 4 years ago, to be generally used by other Firefox subsystems as hardcoded values. While that can change, it's unlikely and would have be for a good reason because of all pre-existing dependencies elsewhere.

That said, their use in WebExtensions is not documented.

Xan
  • 74,770
  • 16
  • 179
  • 206