Contents
Use the chrome.bookmarks
module to create, organize,
and otherwise manipulate bookmarks.
Manifest
You must declare the "bookmarks" permission in your extension's manifest to use the bookmarks API. For example:
{ "name": "My extension that uses bookmarks", "version": "0.1", "permissions": [ "bookmarks" ] }
Description
BookmarkTreeNode objects
are an important part of the chrome.bookmarks
API.
Each bookmark tree node represents
either a URL or a group of bookmarks, as you can see in the following figure.
[PENDING: this figure needs to be updated]
Properties
Objects that represent bookmarks can have the following properties:
-
id
- An integer ID that's unique for each bookmark. IDs are unique and persisted within the current profile and are and stable across shutdown and startup of the browser.
-
title
- The name of the bookmark. This is the user-visible string that describes the URL or group.
-
parentId
(omitted for the root group) - The ID of the group that this bookmark is in.
-
index
(optional; omitted for the root group) - The 0-based integer position of the bookmark within its group.
-
url
(omitted for groups) - The URL of the page that the bookmark points to.
- ...
Examples
The following code creates a bookmark group with the title "Chromium bookmarks". The last argument defines a function to be executed after the folder is created.
chrome.bookmarks.create({'parentId': bookmarkBar.id, 'title': 'Chromium bookmarks'}, function(newFolder) {...});
The next snippet creates a bookmark pointing to the Chromium developer doc. Since nothing too bad will happen if creating the bookmark fails, this snippet doesn't bother to define a callback function.
chrome.bookmarks.create({'parentId': chromiumBookmarks.id, 'title': 'dev doc', 'url': 'http://code.google.com/chrome/extensions'});
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:
Here's some code you could use to create that hierarchy:
[PENDING: ...code goes here...]
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.
-
parentId
( optional string )
- The id of the parent folder node. Not present in the root node.
-
index
( optional integer )
- The 0-based position of this node within its parent.
-
url
( optional string )
- The URL navigated to when a user clicks on the bookmark. This field isn't present for folders.
-
title
( string )
- The text displayed for the node.
-
dateAdded
( optional number )
- When this node was created, represented in milliseconds since the epoch (new Date(dateAdded)).
-
dateGroupModified
( optional number )
- When the contents of this folder last changed, represented in milliseconds since the epoch.
-
children
( optional array of BookmarkTreeNode )
- An ordered list of children of this node.