0

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?

conectionist
  • 2,694
  • 6
  • 28
  • 50

2 Answers2

2

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

Kaspar Lee
  • 5,446
  • 4
  • 31
  • 54
  • Apparently it's TOOLBAR without apostrophes and you have to initialize it with the require statement. I posted an answer to make it clearer. Thank you for your suggestions. – conectionist Mar 20 '16 at 17:53
0

Apparently this is how it's done:

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);
conectionist
  • 2,694
  • 6
  • 28
  • 50