Home | History | Annotate | Download | only in intros
      1 <img src="{{static}}/images/bookmarks.png"
      2      width="486" height="211" alt="Clicking the star adds a bookmark" />
      3 
      4 <h2 id="manifest">Manifest</h2>
      5 <p>You must declare the "bookmarks" permission
      6 in the <a href="manifest">extension manifest</a>
      7 to use the bookmarks API.
      8 For example:</p>
      9 <pre data-filename="manifest.json">
     10 {
     11   "name": "My extension",
     12   ...
     13   <b>"permissions": [
     14     "bookmarks"
     15   ]</b>,
     16   ...
     17 }
     18 </pre>
     19 
     20 <h2 id="description">Objects and properties</h2>
     21 
     22 <p>
     23 Bookmarks are organized in a tree,
     24 where each node in the tree
     25 is either a bookmark or a folder
     26 (sometimes called a <em>group</em>).
     27 Each node in the tree
     28 is represented by a
     29 $(ref:bookmarks.BookmarkTreeNode) object.
     30 </p>
     31 
     32 <p>
     33 <code>BookmarkTreeNode</code> properties
     34 are used throughout the <code>chrome.bookmarks</code> API.
     35 For example, when you call
     36 $(ref:bookmarks.create),
     37 you pass in the new node's parent (<code>parentId</code>),
     38 and, optionally, the node's
     39 <code>index</code>, <code>title</code>, and <code>url</code> properties.
     40 See $(ref:bookmarks.BookmarkTreeNode)
     41 for information about the properties a node can have.
     42 </p>
     43 
     44 <p class="note"><b>Note:</b> You cannot use this API to add or remove entries
     45 in the root folder.  You also cannot rename, move, or remove the special
     46 "Bookmarks Bar" and "Other Bookmarks" folders.</p>
     47 
     48 <h2 id="overview-examples">Examples</h2>
     49 
     50 <p>
     51 The following code creates a folder with the title "Extension bookmarks".
     52 The first argument to <code>create()</code> specifies properties
     53 for the new folder.
     54 The second argument defines a function
     55 to be executed after the folder is created.
     56 </p>
     57 
     58 <pre>
     59 chrome.bookmarks.create({'parentId': bookmarkBar.id,
     60                          'title': 'Extension bookmarks'},
     61                         function(newFolder) {
     62   console.log("added folder: " + newFolder.title);
     63 });
     64 </pre>
     65 
     66 <p>
     67 The next snippet creates a bookmark pointing to
     68 the developer documentation for extensions.
     69 Since nothing bad will happen if creating the bookmark fails,
     70 this code doesn't bother to define a callback function.
     71 </p>
     72 
     73 <pre>
     74 chrome.bookmarks.create({'parentId': extensionsFolderId,
     75                          'title': 'Extensions doc',
     76                          'url': 'http://code.google.com/chrome/extensions'});
     77 </pre>
     78 
     79 <p>
     80 For an example of using this API, see the
     81 <a href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/api/bookmarks/basic/">basic bookmarks sample</a>.
     82 For other examples and for help in viewing the source code, see
     83 <a href="samples">Samples</a>.
     84 </p>
     85