Search code examples
firefox-addon-sdkbookmarks

Programmatically bookmark pages in bookmark toolbar using firefox extension


I'm trying to make a firefox extension that bookmarks the current page and adds an entry in the bookmarks toolbar. Using the example in the documentation found here I was only able to only bookmark a link but not make it appear in the bookmarks toolbar. I was unable to find anything helpful in the documentation or on google related to this.

Here's my code:

let { Bookmark, save } = require("sdk/places/bookmarks");

// Create a new bookmark instance, unsaved
let bookmark = Bookmark({ title: "Test", url: "http://mozilla.org" });

// Attempt to save the bookmark instance to the Bookmarks database
// and store the emitter
let emitter = save(bookmark);

Is this simply not possible or is there something in the documentation that I've overlooked?


Solution

  • Try setting group to TOOLBAR, like so:

    let { Bookmark, TOOLBAR, save } = require("sdk/places/bookmarks");
    
    // Create a new bookmark instance, unsaved
    let bookmark = Bookmark({
        title: "Test",
        url: "http://mozilla.org",
        group: TOOLBAR,
    });
    
    // Attempt to save the bookmark instance to the Bookmarks database
    // and store the emitter
    let emitter = save(bookmark);
    

    There is more information on this part of the page on MDN