connect.bookmarks
Read and modify the profile's favorites tree — links, folders, moves, and change events.
Read and modify the profile's favorites. Favorites are a tree: every entry is either
a link (has a url) or a folder (url: ''), nested via parentId (null = top
level).
- Capabilities:
bookmarks.read(read),bookmarks.write(modify) - Namespace:
connect.bookmarks
An entry is { id, url, title, favicon, createdAt, kind, parentId }.
Walkthrough
Render the favorites and keep them fresh.
- Declare the capabilities:
bookmarks.readto list,bookmarks.writeto modify:{ "capabilities": ["bookmarks.read", "bookmarks.write"] } - Read what you need —
list()for a flat set of links,getTree()for the nested structure. - Modify with
add/createFolder/move/remove. - Re-read on
onChanged— the event carries no diff, so re-fetch to stay current.
Methods
bookmarks.list()
A flat list of every link, at any depth — the common case.
How to use it
- Call it; you get every link (no folders).
- Render directly — no tree-walking needed.
Signature — connect.bookmarks.list() · Capability: bookmarks.read
Returns — Promise<Bookmark[]>. Folders are not included.
bookmarks.getTree()
The nested tree.
How to use it
- Call it when you need folder structure.
- Recurse
childrento render nested folders.
Signature — connect.bookmarks.getTree() · Capability: bookmarks.read
Returns — Promise<Bookmark[]> — roots first; folders carry a children array.
bookmarks.getChildren(parentId?)
Direct children of a folder.
How to use it
- Pass a folder
id, or omit /nullfor the top level. - Use it to lazy-load one folder at a time.
Signature — connect.bookmarks.getChildren(parentId?) · Capability: bookmarks.read
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
parentId | string | null | no | The folder; omit / null for top level. |
Returns — Promise<Bookmark[]> — folders first.
bookmarks.add(url, title?, favicon?, parentId?)
Add a link.
How to use it
- Pass at least the
url; addtitle/parentIdto place it in a folder. - Adding an already-favorited URL returns the existing entry (no duplicate).
Signature — connect.bookmarks.add(url, title?, favicon?, parentId?) ·
Capability: bookmarks.write
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
url | string | yes | The link. An already-favorited URL returns the existing entry. |
title | string | no | Display title. |
favicon | string | no | Favicon URL. |
parentId | string | no | Add straight into a folder. |
Returns — Promise<Bookmark>.
bookmarks.createFolder(title, parentId?)
Create a folder.
How to use it
- Pass a
title(and optionalparentIdto nest it). - Use the returned
idas aparentIdforadd/move.
Signature — connect.bookmarks.createFolder(title, parentId?) · Capability:
bookmarks.write · Returns Promise<Bookmark>.
bookmarks.move(id, parentId?)
Re-parent an entry.
How to use it
- Pass the entry
idand the newparentId(null= top level). - You can't move a folder into itself or a descendant — that's refused.
Signature — connect.bookmarks.move(id, parentId?) · Capability: bookmarks.write
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | yes | The entry to move. |
parentId | string | null | no | New parent; null = top level. |
Returns — Promise<Bookmark>. Refuses to move a folder into itself or its own
descendant.
bookmarks.remove(url)
Delete a link by URL.
How to use it
- Pass the
urlof the link to un-favorite.
Signature — connect.bookmarks.remove(url) · Capability: bookmarks.write ·
Returns Promise<void>.
bookmarks.removeById(id)
Delete by id.
How to use it
- Pass an entry
id. - Be careful with a folder id — it deletes the whole subtree.
Signature — connect.bookmarks.removeById(id) · Capability: bookmarks.write
Returns — Promise<void>. Deleting a folder takes its whole subtree with it.
Events
bookmarks.onChanged(cb)
Fires on any favorites change in the profile — yours or the user starring a page.
How to use it
- Subscribe once.
- On each fire, re-read with
getTree/list(the event carries no diff). - Keep the returned function to unsubscribe.
Payload — none. The event carries no diff — re-read on each fire.
const off = connect.bookmarks.onChanged(async () => {
render(await connect.bookmarks.getTree());
});Notes
- Ordering inside a folder is by creation time; there's no explicit index yet.
- Feature-detect
bookmarks.read/bookmarks.writeindependently.