You must declare the "bookmarks" permission in the extension manifest to use the bookmarks API. For example:
{ "name": "My extension", ... "permissions": [ "bookmarks" ], ... }
Bookmarks are organized in a tree, where each node in the tree is either a bookmark or a folder (sometimes called a group). Each node in the tree is represented by a $ref:bookmarks.BookmarkTreeNode object.
BookmarkTreeNode
properties
are used throughout the chrome.bookmarks
API.
For example, when you call
$ref:bookmarks.create,
you pass in the new node's parent (parentId
),
and, optionally, the node's
index
, title
, and url
properties.
See $ref:bookmarks.BookmarkTreeNode
for information about the properties a node can have.
Note: You cannot use this API to add or remove entries in the root folder. You also cannot rename, move, or remove the special "Bookmarks Bar" and "Other Bookmarks" folders.
The following code creates a folder with the title "Extension bookmarks".
The first argument to create()
specifies properties
for the new folder.
The second argument defines a function
to be executed after the folder is created.
chrome.bookmarks.create({'parentId': bookmarkBar.id, 'title': 'Extension bookmarks'}, function(newFolder) { console.log("added folder: " + newFolder.title); });
The next snippet creates a bookmark pointing to the developer documentation for extensions. Since nothing bad will happen if creating the bookmark fails, this code doesn't bother to define a callback function.
chrome.bookmarks.create({'parentId': extensionsFolderId, 'title': 'Extensions doc', 'url': 'http://code.google.com/chrome/extensions'});
For an example of using this API, see the basic bookmarks sample. For other examples and for help in viewing the source code, see Samples.