bookmarks Permission — Chrome Extension Reference
4 min readbookmarks Permission — Chrome Extension Reference
Overview
- Permission string:
"bookmarks" - What it grants: Full access to
chrome.bookmarksAPI — read, create, update, delete, move, search bookmarks - Risk level: Medium — full access to user’s bookmark tree
- User prompt: “Read and change your bookmarks”
@theluckystrike/webext-permissionsdescription:describePermission('bookmarks')
manifest.json Setup
{
"permissions": ["bookmarks"]
}
- Consider using
optional_permissionsif bookmarks are a secondary feature - Request at runtime with
@theluckystrike/webext-permissions:const result = await requestPermission('bookmarks'); if (result.granted) { /* use chrome.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"
});
- Returns the full bookmark tree as nested
BookmarkTreeNodeobjects
chrome.bookmarks.get(idOrIds)
chrome.bookmarks.get("123", (results) => {
console.log(results[0].title, results[0].url);
});
chrome.bookmarks.getChildren(id)
- Get direct children of a folder
chrome.bookmarks.search(query)
chrome.bookmarks.search({ query: "github" }, (results) => {
results.forEach(b => console.log(b.title, b.url));
});
- Search by title, URL, or both
- Also accepts string shorthand:
chrome.bookmarks.search("github", cb)
Creating Bookmarks
chrome.bookmarks.create(bookmark)
chrome.bookmarks.create({
parentId: "1", // "1" = Bookmarks Bar
title: "My Site",
url: "https://example.com"
});
- Omit
urlto create a folder indexcontrols position within parent
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)
remove— delete a single bookmarkremoveTree— delete a folder and all its contents
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}`);
});
- React to bookmark changes in real-time
- Works in background service worker
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
- Read tree, display in custom UI, allow CRUD operations
- Persist user preferences with
@theluckystrike/webext-storage
Bookmark Sync/Export
getTree()to read all, serialize to JSON/HTML- Import by iterating and calling
create()
Duplicate Finder
getTree(), flatten, group by URL, find duplicates
Bookmark Search from Popup
- Quick search popup using
chrome.bookmarks.search() - Show results in extension 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
"Can't modify the root bookmark folders"— IDs “0”, “1”, “2” are system folders"Can't remove non-empty folder"— useremoveTreefor folders with children- Bookmark ID not found — bookmarks may have been deleted by user
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.