Search code examples
javascriptfirefoxfirefox-addonfirefox-addon-sdk

Can I add my own root-level bookmark groups in Firefox via an add-on?


Firefox comes with three top-level bookmark groups: Bookmarks Toolbar, Bookmarks Menu, and Unsorted Bookmarks. You can see the three groups by clicking "Show All Bookmarks" on the "Bookmarks" menu.

I am working on a Firefox add-on and would like to add a new type of root-level bookmark category. By using the built-in bookmark system to store bookmarks for my add-on, the add-on can take advantage of a familiar interface and tools like Firefox Sync. The use cases for the add-on make more sense if the add-on's bookmarks are stored separately from the user's traditional bookmarks. That is to say, I want to create a new group alongside the built-in "Bookmarks Toolbar," "Bookmarks Menu," and "Unsorted Bookmarks," and store my bookmarks in this new group.

Built-in bookmark groups in Firefox

I haven't been able to find any documentation or examples that demonstrate if adding a new top-level bookmark category is possible. Can anyone say if this is possible and, if it is not, why this isn't allowed?


Solution

  • The creation of root folders is possible, but Places UI does not treat them as equals to the built-ins.

    If you want, you can open the Library focused to a specific folder

    var myfolderid; // the id returned by createFolder or otherwise obtained
    PlacesCommandHook.showPlacesOrganizer(myfolderid);
    

    Code not running in the context of ChromeWindow should get a reference to one. For Add-on SDK extension that would be something like

    const { getMostRecentBrowserWindow } = require('sdk/window/utils');
    getMostRecentBrowserWindow().PlacesCommandHook.showPlacesOrganizer(myfolderid);