Programmatically bookmark pages in bookmark toolbar using firefox extension

不打扰是莪最后的温柔 提交于 2019-12-12 03:26:40

问题


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?


回答1:


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




回答2:


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);


来源:https://stackoverflow.com/questions/36112538/programmatically-bookmark-pages-in-bookmark-toolbar-using-firefox-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!