bookmarks Permission — Chrome Extension Reference

4 min read

bookmarks Permission — Chrome Extension Reference

Overview

manifest.json Setup

{
  "permissions": ["bookmarks"]
}

Key APIs

Reading Bookmarks

chrome.bookmarks.getTree()

chrome.bookmarks.getTree((tree) => {
  // tree[0] is the root node
  // tree[0].children[0] = "Bookmarks Bar"
  // tree[0].children[1] = "Other Bookmarks"
});

chrome.bookmarks.get(idOrIds)

chrome.bookmarks.get("123", (results) => {
  console.log(results[0].title, results[0].url);
});

chrome.bookmarks.getChildren(id)

chrome.bookmarks.search(query)

chrome.bookmarks.search({ query: "github" }, (results) => {
  results.forEach(b => console.log(b.title, b.url));
});

Creating Bookmarks

chrome.bookmarks.create(bookmark)

chrome.bookmarks.create({
  parentId: "1",  // "1" = Bookmarks Bar
  title: "My Site",
  url: "https://example.com"
});

Modifying Bookmarks

chrome.bookmarks.update(id, changes)

chrome.bookmarks.update("123", { title: "New Title", url: "https://new-url.com" });

chrome.bookmarks.move(id, destination)

chrome.bookmarks.move("123", { parentId: "2", index: 0 });

chrome.bookmarks.remove(id) / removeTree(id)

Events

chrome.bookmarks.onCreated

chrome.bookmarks.onRemoved

chrome.bookmarks.onChanged

chrome.bookmarks.onMoved

chrome.bookmarks.onChildrenReordered

chrome.bookmarks.onImportBegan

chrome.bookmarks.onImportEnded

chrome.bookmarks.onCreated.addListener((id, bookmark) => {
  console.log(`New bookmark: ${bookmark.title} at ${bookmark.url}`);
});

BookmarkTreeNode Structure

interface BookmarkTreeNode {
  id: string;
  parentId?: string;
  index?: number;
  url?: string;        // undefined for folders
  title: string;
  dateAdded?: number;   // timestamp
  dateGroupModified?: number;
  dateLastUsed?: number; // last opened timestamp (Chrome 114+)
  unmodifiable?: "managed"; // set for admin-configured bookmarks
  children?: BookmarkTreeNode[];  // only for folders
}

Common Patterns

Bookmark Manager

Bookmark Sync/Export

Duplicate Finder

Bookmark Search from Popup

Storage Integration

import { createStorage, defineSchema } from '@theluckystrike/webext-storage';
const storage = createStorage(defineSchema({
  lastBookmarkSync: 'number',
  bookmarkCount: 'number'
}), 'local');

// Track bookmark count
chrome.bookmarks.getTree(async (tree) => {
  const count = countBookmarks(tree);
  await storage.set('bookmarkCount', count);
});

Common Errors

API Reference

Frequently Asked Questions

How do I bookmark pages in a Chrome extension?

Use the chrome.bookmarks API to create, read, update, and delete bookmarks. You can create folders, organize bookmarks, and listen for changes via chrome.bookmarks.onCreated and other events.

Can extensions read user’s existing bookmarks?

Yes, with the “bookmarks” permission, your extension can read and manipulate the user’s existing bookmarks. —

Part of the Chrome Extension Guide by theluckystrike. Built at zovo.one.

No previous article
No next article