Contents
Use the chrome.bookmarks
module to create, organize,
and otherwise manipulate bookmarks.
Manifest
You must declare the "bookmarks" permission in the extension manifest to use the bookmarks API. For example:
{ "name": "My extension that uses bookmarks", "version": "0.1", "permissions": [ "bookmarks" ], ... }
Objects and properties
Bookmarks are organized in a tree,
where each node in the tree
is either a bookmark or a group
(a folder that can contain nodes).
Each node in the tree
is represented by a
BookmarkTreeNode
object.
BookmarkTreeNode
properties
are used throughout the chrome.bookmarks
API.
For example, when you call
create()
,
you pass in the new node's parent (parentId
),
and, optionally, the node's
index
, title
, and url
properties.
See BookmarkTreeNode
for information about the properties a node can have.
[PENDING: The following section needs to be updated or deleted.]
Say you have bookmark hierarchy that looks like this:
- Bookmarks
- Apps
- ...
- ...
- ...
- Google homepage
- Example
Here's how those bookmarks might be represented with bookmark objects:
Examples
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 a full example of using bookmarks, see the bookmarks sample.
API reference: chrome.bookmarks
Methods
create
Creates a bookmark or folder under the specified parentId. If url is NULL or missing, it will be a folder.
Parameters
-
bookmark
( object )
- Undocumented.
-
-
parentId
( string )
- Undocumented.
-
index
( optional integer )
- Undocumented.
-
title
( optional string )
- Undocumented.
-
url
( optional string )
- Undocumented.
-
parentId
-
callback
( optional function )
- Undocumented.
Returns
Callback function
If you specify the callback parameter, it should specify a function that looks like this:
function(BookmarkTreeNode result) {...});
-
result
( BookmarkTreeNode )
- Undocumented.
get
Retrieves the specified BookmarkTreeNode(s).
Parameters
-
idOrIdList
( string or array of string )
- A single string-valued id, or an array of string-valued ids
-
callback
( function )
- Undocumented.
Returns
Callback function
If you specify the callback parameter, it should specify a function that looks like this:
function(array of BookmarkTreeNode results) {...});
-
results
( array of BookmarkTreeNode )
- Undocumented.
getChildren
Retrieves the children of the specified BookmarkTreeNode id.
Parameters
-
id
( string )
- Undocumented.
-
callback
( function )
- Undocumented.
Returns
Callback function
If you specify the callback parameter, it should specify a function that looks like this:
function(array of BookmarkTreeNode results) {...});
-
results
( array of BookmarkTreeNode )
- Undocumented.
getTree
Retrieves the entire Bookmarks hierarchy.
Parameters
-
callback
( function )
- Undocumented.
Returns
Callback function
If you specify the callback parameter, it should specify a function that looks like this:
function(array of BookmarkTreeNode results) {...});
-
results
( array of BookmarkTreeNode )
- Undocumented.
move
Moves the specified BookmarkTreeNode to the provided location.
Parameters
-
id
( string )
- Undocumented.
-
destination
( object )
- Undocumented.
-
-
parentId
( string )
- Undocumented.
-
index
( optional integer )
- Undocumented.
-
parentId
-
callback
( optional function )
- Undocumented.
Returns
Callback function
If you specify the callback parameter, it should specify a function that looks like this:
function(BookmarkTreeNode result) {...});
-
result
( BookmarkTreeNode )
- Undocumented.
remove
Removes a bookmark or an empty bookmark folder.
Parameters
-
id
( string )
- Undocumented.
-
callback
( optional function )
- Undocumented.
Returns
Callback function
If you specify the callback parameter, it should specify a function that looks like this:
function() {...});
removeTree
Recursively removes a bookmark folder.
Parameters
-
id
( string )
- Undocumented.
-
callback
( optional function )
- Undocumented.
Returns
Callback function
If you specify the callback parameter, it should specify a function that looks like this:
function() {...});
search
Seaches for BookmarkTreeNodes matching the given query.
Parameters
-
query
( string )
- Undocumented.
-
callback
( function )
- Undocumented.
Returns
Callback function
If you specify the callback parameter, it should specify a function that looks like this:
function(array of BookmarkTreeNode results) {...});
-
results
( array of BookmarkTreeNode )
- Undocumented.
update
Updates the properties of a bookmark or folder. Only specify the properties that you want to change, unspecified properties will be left unchanged. NOTE: currently, only 'title' is supported.
Parameters
-
id
( string )
- Undocumented.
-
changes
( object )
- Undocumented.
-
-
title
( optional string )
- Undocumented.
-
title
-
callback
( optional function )
- Undocumented.
Returns
Callback function
If you specify the callback parameter, it should specify a function that looks like this:
function(BookmarkTreeNode result) {...});
-
result
( BookmarkTreeNode )
- Undocumented.
Events
onChanged
Fired when a bookmark or folder changes. NOTE: currently, only title changes trigger this.
Parameters
-
id
( string )
- Undocumented.
-
changeInfo
( object )
- Undocumented.
-
-
title
( string )
- Undocumented.
-
title
onChildrenReordered
Fired when the children of a folder have changed their order due to the order being sorted in the UI. This is not called as a result of a move().
Parameters
-
id
( string )
- Undocumented.
-
reorderInfo
( object )
- Undocumented.
-
-
childIds
( array of string )
- Undocumented.
-
childIds
onCreated
Fired when a bookmark or folder is created.
Parameters
-
id
( string )
- Undocumented.
-
bookmark
( BookmarkTreeNode )
- Undocumented.
onMoved
Fired when a bookmark or folder is moved to a different parent folder.
Parameters
-
id
( string )
- Undocumented.
-
moveInfo
( object )
- Undocumented.
-
-
parentId
( string )
- Undocumented.
-
index
( integer )
- Undocumented.
-
oldParentId
( string )
- Undocumented.
-
oldIndex
( integer )
- Undocumented.
-
parentId
onRemoved
Fired when a bookmark or folder is removed. When a folder is removed recursively, a single notification is fired for the folder, and none for its contents.
Parameters
-
id
( string )
- Undocumented.
-
removeInfo
( object )
- Undocumented.
-
-
parentId
( string )
- Undocumented.
-
index
( integer )
- Undocumented.
-
parentId
Types
BookmarkTreeNode
-
id
( string )
- The unique identifier for the node. IDs are unique within the current profile, and they remain valid even after the browser is restarted.
-
parentId
( optional string )
- The
id
of the parent folder. Omitted for the root node. -
index
( optional integer )
- The 0-based position of this node within its parent folder.
-
url
( optional string )
- The URL navigated to when a user clicks the bookmark. Omitted for folders.
-
title
( string )
- The text displayed for the node.
-
dateAdded
( optional number )
- When this node was created, in milliseconds since the epoch (
new Date(dateAdded)
). -
dateGroupModified
( optional number )
- When the contents of this folder last changed, in milliseconds since the epoch.
-
children
( optional array of BookmarkTreeNode )
- An ordered list of children of this node.
[PENDING: Update and introduce the following image or delete the file.]