Browser extension capture
The browser extension gives a user a fast way to send the current page, a link, or selected text to Karakeep. It keeps the connection and login details in browser storage, can capture a page in the browser when the user opts in, and gives immediate feedback after save or delete actions. This page is a child of Client integrations; see also Mobile application, Developer tool integrations, and Integration operations APIs.
Extension role
Capture entry points
The extension popup is the main save surface, while browser context menus and the Ctrl+Shift+E command provide quick entry points. These paths turn the current page into a link bookmark or turn selected text into a text bookmark before the popup asks the user to save it.
The background service worker also checks whether the current URL is already saved. When the count badge is enabled, it shows that state on the extension icon. The user can use the context menu to open the matching bookmark or search for the URL when there is no exact match.
flowchart LR
A[Current page] --> B[Popup]
A --> C[Context menu or keyboard command]
C --> D[Pending bookmark request]
B --> E[Save or confirm]
D --> E
E --> F[Karakeep bookmark]
A --> G[URL status check]
G --> H[Badge or bookmark search]
References: apps/…/manifest.json• L11-18 apps/…/manifest.json• L47-70 apps/…/background.ts• L50-75 apps/…/background.ts• L99-137 apps/…/background.ts• L264-285 apps/…/SavePage.tsx• L81-115
Configuration state
The extension starts with a Karakeep server address and stores its settings in synchronized browser storage. The address must use HTTP or HTTPS, and the extension removes a trailing slash before it builds API URLs.
Settings control the user experience around saving and status checks:
autoSavesaves a pending bookmark as soon as it is ready. When it is off, the user can review the title and add a note first.- Client-side crawling asks for page access only when the user enables it. The permission can later be revoked in browser settings.
- The count badge and its cache control whether the icon checks and displays bookmark status for the current URL.
- The theme and image option adjust the extension display and page-capture result.
When the address or login changes, the extension switches its API context. It clears data tied to the old context so a new server or user does not reuse old cached results.
References: apps/…/NotConfiguredPage.tsx• L10-37 apps/…/settings.ts• L7-36 apps/…/settings.ts• L38-87 apps/…/trpc.ts• L23-67 apps/…/OptionsPage.tsx• L35-67
Authentication boundary
Login methods
The extension uses an API key for all later Karakeep requests. A user can enter an email and password, which the server exchanges for a new API key, or can enter an existing API key, which the server validates before use.
The generated key is named as an extension key so it can be identified and revoked. On logout, the extension clears its local key and revokes the generated key when it has its key identifier. The server applies rate limits and can reject password exchange when password login or required email verification does not allow it.
References: apps/…/SignInPage.tsx• L11-45 apps/…/SignInPage.tsx• L65-90 apps/…/OptionsPage.tsx• L69-109 packages/…/apiKeys.ts• L132-214
API request context
The extension sends the API key as a bearer token to the configured server. Its request client covers the tRPC service, while page-archive uploads use the same identity at the asset endpoint. This shared request context lets a bookmark and its optional captured archive belong to the same user.
The extension also keeps a short-lived status cache for URL checks. A server or key change discards that cache, and a successful save or delete invalidates the current URL status so the icon does not show stale information.
References: apps/…/trpc.ts• L71-111 apps/…/singlefile.ts• L98-139 apps/…/badgeCache.ts• L11-46 apps/…/background.ts• L345-360
Page capture
Client-side archive
Client-side crawling is an optional capture mode for link bookmarks. It uses the browser view of the active page to make an HTML archive before the bookmark is created, which can preserve content that a server fetch may not see in the same way.
The capture path applies only when the bookmark URL is the active tab URL and the user has granted page access. It can include or omit images. The captured HTML is uploaded as an asset, and the new bookmark points to that asset. If capture fails or the browser blocks the page, the extension still saves the link without the archive.
sequenceDiagram
participant U as User
participant P as Popup
participant T as Active tab
participant S as Karakeep server
U->>P: Save link
P->>P: Check opt-in and URL match
P->>T: Request page capture
T-->>P: HTML archive
P->>S: Upload archive
S-->>P: Asset identifier
P->>S: Create bookmark with archive reference
S-->>P: Bookmark result
P-->>U: Saved feedback
The browser permission is an explicit opt-in because capture can read page content. Turning the feature off removes that permission. This mode is separate from context-menu saves for a link or image target, because capturing the active page for a different target would attach the wrong page to the bookmark.
References: apps/…/OptionsPage.tsx• L49-67 apps/…/permissions.ts• L1-24 apps/…/SavePage.tsx• L122-159 apps/…/singlefile.ts• L12-39 apps/…/singlefile.ts• L98-139 apps/…/singlefile-content-script.ts• L22-66
Bookmark types
The extension can submit the bookmark types supported by its entry points. A page, link, or image becomes a link bookmark; selected text becomes a text bookmark; and the popup can also display asset requests passed from another extension action.
When auto-save is off, the popup lets the user check the link title or asset title and add a note before sending the request. The server then creates the bookmark and starts the normal downstream processing for that bookmark type.
References: apps/…/background.ts• L140-183 apps/…/SavePage.tsx• L106-115 apps/…/SavePage.tsx• L218-293 packages/…/bookmarks.ts• L240-257 packages/…/bookmarks.ts• L332-565
Bookmark feedback
Save result
After a successful save, the popup moves to a bookmark result view instead of leaving the user on the save form. That view confirms the bookmark, links to its Karakeep preview, and exposes the small follow-up actions that are useful immediately after capture.
Save errors remain in the popup and prevent the success view. The background service refreshes the URL badge after a save on a best-effort basis, so a temporary inability to reach the background worker does not undo a successful server save.
References: apps/…/SavePage.tsx• L41-67 apps/…/SavePage.tsx• L190-217 apps/…/BookmarkSavedPage.tsx• L18-43 apps/…/BookmarkSavedPage.tsx• L51-98
Bookmark editing
The result view provides a focused editing surface for the new bookmark. A user can add or change a note, attach or remove tags, and add or remove the bookmark from lists without opening the full web dashboard.
These edits use the shared bookmark operations, so the same bookmark ownership rules and query refresh behavior apply to extension edits as to other clients. List choices exclude lists where the user has viewer-only access.
References: apps/…/NoteEditor.tsx• L12-49 apps/…/TagsSelector.tsx• L25-56 apps/…/ListsSelector.tsx• L26-59 apps/…/BookmarkLists.tsx• L12-45 packages/…/bookmarks.ts• L74-129
Deletion result
The result view lets the user delete the bookmark they just saved. On success, the extension refreshes the URL badge and moves to a separate deletion confirmation view. If deletion fails, it keeps the bookmark view open and shows the error instead of claiming that the bookmark was removed.
The shared delete operation also removes the deleted bookmark from client query state. This keeps later extension reads from presenting the removed item as current.
References: apps/…/BookmarkSavedPage.tsx• L23-43 apps/…/BookmarkDeletedPage.tsx• L1-3 packages/…/bookmarks.ts• L74-100 packages/…/bookmarks.ts• L805-813
Custom headers
Header configuration
Custom headers let the extension reach a Karakeep server that needs an extra request header, such as a gateway or access layer. The user can add, replace, or remove named header values from the setup and login screens.
The extension stores headers as a name-to-value map. Empty names and values are not saved. A change to the header map causes the request context and its persisted cache to be rebuilt, which prevents results from one request context from being reused in another.
References: apps/…/CustomHeadersPage.tsx• L10-68 apps/…/NotConfiguredPage.tsx• L54-65 apps/…/SignInPage.tsx• L166-176 apps/…/settings.ts• L7-19 apps/…/trpc.ts• L27-55
Header delivery
Configured headers are sent with every tRPC API request and with the upload that carries a client-side page archive. The bearer API key remains part of the request as well, so custom headers extend the connection path rather than replace Karakeep authentication.
The same header set must work for both normal API calls and asset uploads when client-side crawling is enabled. A header that only permits one of these paths can make a save fail after capture even though login and ordinary bookmark requests work.
References: apps/…/trpc.ts• L98-109 apps/…/singlefile.ts• L114-135 packages/…/trpc-provider.tsx• L42-93
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the settings schema, the setup screens, and API-client reinitialization aligned when adding or renaming a connection setting.
- Keep the bearer key and custom headers aligned between tRPC requests and archive uploads. A mismatch can break only client-side crawling.
- Keep the capture URL-match rule aligned with context-menu bookmark targets. Otherwise a saved link can receive an archive from the wrong tab.
- Keep save and delete success handlers aligned with badge invalidation. The icon can otherwise report an old bookmark state after the server has changed.
- Keep generated API-key ownership and logout behavior aligned. A key created for the extension should not remain active after the user logs out.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Server address is empty or is not HTTP/HTTPS | The extension cannot build a valid API endpoint | Setup validation requires a non-empty HTTP or HTTPS address. |
| API key is invalid or revoked | API queries and bookmark mutations fail | Login validates a supplied key, and logout clears local credentials and revokes generated keys. |
| Client-side capture lacks host permission or the page blocks capture | No archive is attached to the bookmark | Capture is opt-in and best effort; the extension falls back to saving the link without an archive. |
| The active tab URL differs from a context-menu target | Capturing the active page would archive the wrong resource | Capture runs only when the bookmark URL matches the active tab URL. |
| A custom header is accepted by the API but not by the asset endpoint | The bookmark may fail after its page archive upload starts | Send and validate the same custom-header set across API calls and asset uploads. |
| Badge cache is not invalidated after save or delete | The extension icon shows stale bookmark status | Successful save and delete flows clear the URL status before refreshing the badge. |
Key files
| File | Why to read it |
|---|---|
| apps/…/manifest.json | Defines the browser entry points, permissions, optional page access, and background worker. |
| apps/…/SavePage.tsx | Shows how popup input becomes a bookmark and how optional page capture fits before creation. |
| apps/…/background.ts | Explains context-menu capture requests, keyboard saves, URL status checks, and badge refresh. |
| apps/…/SignInPage.tsx | Shows the two extension login paths and where custom-header setup is exposed. |
| apps/…/OptionsPage.tsx | Describes user settings for save behavior, page access, badges, and logout. |
| apps/…/settings.ts | Defines the connection and capture state shared by popup and background contexts. |
| apps/…/trpc.ts | Shows how the configured server, bearer key, headers, and cache form one API context. |
| apps/…/singlefile.ts | Shows the boundary between browser HTML capture, asset upload, and bookmark creation. |
| apps/…/BookmarkSavedPage.tsx | Shows post-save actions and deletion feedback. |
| apps/…/CustomHeadersPage.tsx | Shows how custom headers are added, changed, removed, and stored. |
| packages/…/apiKeys.ts | Defines server-side API-key exchange, validation, and revocation used by the extension. |
| packages/…/bookmarks.ts | Defines the bookmark create and delete service operations called by the extension. |
| packages/…/bookmarks.ts | Connects extension bookmark edits and deletion to shared query refresh behavior. |