Web clipper extension
The web clipper extension lets a user send useful parts of a web session to Trilium. It turns page content, links, images, screenshots, notes, PDFs, and browser tabs into note data, then sends that data to a local desktop instance or a configured Trilium server.
System role
The extension is a browser-side capture client. It keeps the browser page unchanged during normal capture while it prepares selected content for storage as a Trilium note and its related attachments.
The extension belongs to the wider client platform described in Platform clients. Its local desktop relationship is described in Desktop shell and IPC, while browser-only runtime context is described in Standalone browser runtime. Its server-facing contract is part of the server clipper API.
Extension entrypoints
The extension divides browser work by where that work must run. The background entrypoint coordinates actions and network calls. The content entrypoint reads the active page. Popup and options pages provide user controls.
Background coordinator
The background coordinator is the main path from a browser action to a Trilium request. It receives commands from the popup, keyboard shortcuts, context menus, and page scripts. It then asks the content script for page data or uses browser capture services for screenshots before it reports the result in the active tab.
Its actions support two broad outcomes:
- Capture page material such as a selection, readable page, link, image, PDF, screenshot, or browser tab list.
- Manage the Trilium connection and follow-up actions such as opening a saved note or closing tabs after a tab-list save.
References: apps/…/index.ts• L78-121 apps/…/index.ts• L292-350 apps/…/index.ts• L723-847
Browser-facing entrypoints
The content entrypoint runs on web pages and returns page data to the background coordinator. The popup exposes save actions and connection state. The options page stores the optional desktop port and the server URL and token needed when the extension cannot use the local desktop instance.
Context-menu actions cover page, selection, link, and image targets. An in-page toast gives the user a save result and a link to the new Trilium note.
References: apps/…/index.ts• L7-11 apps/…/main.tsx• L15-45 apps/…/main.tsx• L47-121 apps/…/main.tsx• L124-245 apps/…/index.ts• L145-184
Capture and content preparation
The capture flow keeps the browser as the source of page context and Trilium as the source of note storage. Each path produces data with a title, HTML or image content, the source URL, and any labels needed by the server.
The diagram shows the common path from a user action to stored Trilium content.
flowchart LR
A[User action] --> B[Popup, shortcut, or context menu]
B --> C[Background coordinator]
C --> D{Capture kind}
D -->|Selection or page| E[Content script]
D -->|Screenshot| F[Browser capture service]
D -->|Link, image, PDF, or tabs| G[Browser action data]
E --> H[Normalize content and image references]
F --> H
G --> H
H --> I[Trilium clipper API]
I --> J[Note and attachment]
Page capture
A selection capture preserves selected HTML and records the page title and full source URL. A page capture uses a readability pass to isolate the main article. It removes page noise and makes links absolute. It also records published or modified dates when the page exposes them.
The readability pass works on a copy of the document. This protects the page that the user is viewing while the extension prepares content for Trilium. If the page does not produce a readable article, the capture reports no usable result instead of sending a partial page.
References: apps/…/index.ts• L185-211 apps/…/index.ts• L584-601 apps/…/index.ts• L649-657 apps/…/Readability.js• L865-872 apps/…/Readability.js• L1265-1317
Media and URL normalization
The extension changes relative links into absolute links so that saved content still points to the original web resources. It replaces image sources in the HTML with temporary image identifiers and sends the matching image data as separate payload items.
The background layer turns image URLs and data images into data URLs when possible. This gives the server the bytes needed to create Trilium attachments instead of leaving the note dependent on the source page. Failed image downloads remain identifiable to the server so it can apply fallback handling.
References: apps/…/index.ts• L193-210 apps/…/index.ts• L447-505
Screenshot and tab capture
Screenshot capture uses the browser’s visible-tab image. Cropped capture first asks the page for a user-drawn rectangle. It then applies the device scale and browser zoom. Full-page capture moves through the page, removes visual elements that would repeat, and joins the captured parts into one or more images. A separate browser document performs the crop and stitching when the selected browser manifest needs an offscreen document.
The tab action creates one HTML list note for the current window. It gives the note a short title based on the tab count and common domains. The save result can then offer to close the included tabs.
References: apps/…/index.ts• L18-143 apps/…/index.ts• L146-341 apps/…/index.ts• L554-573 apps/…/index.ts• L678-733 apps/…/index.ts• L1-23
Page-state preparation
Page-state preparation makes full-page screenshots readable without changing the page after capture. It hides scrollbars and repeated fixed elements, turns sticky elements into normal page content, and restores the page’s inline styles after the capture. A timeout restores the page if the capture flow stops before its final restore request.
References: apps/…/floating_elements.ts• L1-15 apps/…/floating_elements.ts• L49-83 apps/…/floating_elements.ts• L91-140 apps/…/index.ts• L232-235
Trilium connection
The extension supports a local desktop connection and an optional server connection. It checks the desktop instance first. It uses the configured server as a fallback so the capture workflow stays the same when the preferred instance is unavailable.
Instance discovery
The connection layer uses a handshake before it sends clip data. The handshake identifies Trilium and returns a clipper protocol version. A major-version mismatch blocks normal use and gives the popup enough state to show which side needs an update.
The extension keeps connection state for the popup and checks it at regular intervals. The popup uses this state to disable actions that need Trilium. It can also check whether the current page URL already has a matching saved note.
References: apps/…/trilium_server_facade.ts• L1-19 apps/…/trilium_server_facade.ts• L29-89 apps/…/trilium_server_facade.ts• L91-155 apps/…/popup.ts• L119-174
API exchange
After it finds an instance, the background layer sends JSON to the clipper API. Local desktop requests use the local integration path. Server requests use the token obtained during options setup. Each request also carries the browser’s local date and time so Trilium can apply the user’s local context.
The server handles accumulated clippings and standalone notes as separate outcomes. A clipping groups content by source URL and can append to an existing clipping note. A standalone note keeps its clip type and optional labels. In both cases, the server cleans the content, stores usable images as attachments, replaces temporary image identifiers with attachment URLs, and places the result in the clipper inbox or the current day note.
Opening a saved note stays within the current client. Electron can open the note through its local client link. A web-only connection opens the note in the browser.
References: apps/…/trilium_server_facade.ts• L157-234 apps/…/routes.ts• L137-144 apps/…/clipper.ts• L16-58 apps/…/clipper.ts• L89-137 apps/…/clipper.ts• L139-183
Build and release configuration
The extension uses WXT to turn its entrypoints into browser packages. The package provides separate development, build, ZIP, and validation commands for the default browser target and Firefox. Its install step prepares WXT before development or build work.
The package uses WXT 0.21.5. Its browser commands and test commands remain the same: development uses dev or dev:firefox, builds use build or build:firefox, archives use zip or zip:firefox, and validation uses test or coverage. Dependency installation runs postinstall to prepare WXT.
The generated manifest grants access to active pages, tabs, synced settings, context menus, and web hosts. It enables the offscreen permission for Manifest V3 builds that use the offscreen screenshot helper. It defines save commands for the main capture actions. The package also keeps browser development profiles so toolbar and extension settings survive local development runs.
Browser packages
The package creates installable archives with browser-specific commands. The options and popup pages are part of the user-facing package. The offscreen page is excluded from browsers that do not support that path. Archive names identify the extension version and browser.
The source archive also carries the workspace inputs needed to reproduce the build. The archive hook restores the offscreen page and the build instructions when WXT omits that browser-specific entrypoint from the generated source set. Firefox development places the extension action in the browser toolbar.
The main package commands are:
devanddev:firefoxfor local browser development.buildandbuild:firefoxfor browser builds.zipandzip:firefoxfor installable archives.testfor the extension test suite andcoveragefor its coverage report.postinstallto prepare WXT after dependencies are installed.
References: apps/…/package.json• L1-31 apps/…/wxt.config.ts• L7-22 apps/…/wxt.config.ts• L23-79 apps/…/wxt.config.ts• L80-103 apps/…/wxt.config.ts• L105-125 apps/…/wxt.config.ts• L129-133 apps/…/main.tsx• L10-15 apps/…/index.html• L1-9
Automated distribution
The web clipper workflow runs when its app changes or when a web-clipper release tag is pushed. It builds the default browser archive and the Firefox archive. Pull requests and non-release pushes publish the archives as workflow artifacts. Release tags attach them to a GitHub release.
References: .github/…/web-clipper.yml• L1-22 .github/…/web-clipper.yml• L24-57 .github/…/web-clipper.yml• L60-69
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the payload fields produced by the content and background entrypoints aligned with the server’s
notes,clippings, andfilesroutes. A field mismatch can create a note without its source URL, clip type, labels, media, or PDF data. - Update the handshake protocol contract on both the extension and Trilium side when a new required capability changes the major version.
- Keep the local-first and server-fallback connection rules aligned with the server’s authentication rule. Local Electron calls and authenticated server calls do not use the same access path.
- Keep the manifest’s browser permissions, offscreen entrypoint rules, and full-page page-state changes aligned with the screenshot path for each supported browser.
- Keep ZIP artifact names, source archive contents, release-tag rules, browser package commands, and validation commands aligned across wxt.config.ts, package.json, and the web clipper workflow.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| No desktop instance and no valid configured server | Save actions wait for discovery and then fail without a Trilium note | Configure the server in Options or start the local instance. Use the popup connection status before saving. |
| Extension and Trilium report different protocol major versions | The popup reports an incompatible instance and keeps save actions unavailable | Upgrade the older side before changing capture behavior. |
| A page has no usable readable content | Whole-page capture returns no data and does not save a misleading article | Use selection capture or another capture mode for pages that do not expose article content. |
| Image download or conversion does not produce a data URL | The image may stay as an unresolved placeholder or require server fallback handling | Keep image identifiers and source values valid until server processing completes. |
| The page state is not restored after a full-page capture | Scrollbars, sticky elements, or fixed elements can remain changed in the user’s page | Preserve the restore step and the timeout fallback in the page-state preparation path. |
| The offscreen screenshot entrypoint is missing from a supported MV3 build | Cropped screenshot or stitching cannot return an image | Preserve the manifest-specific offscreen entrypoint and source-archive inclusion rules. |
| A server request lacks a valid token | The configured server rejects the handshake or save request | Obtain a token through the options page and keep the stored server URL paired with it. |
Key files
| File | Why to read it |
|---|---|
| apps/…/index.ts | Shows how user actions become captures, payloads, API calls, and save feedback. |
| apps/…/index.ts | Shows the browser-side contract for selections, page state, metadata, and screenshot rectangles. |
| apps/…/floating_elements.ts | Shows how full-page capture avoids repeated page elements and restores page state. |
| apps/…/main.tsx | Shows how the extension configures the local desktop port and obtains server authentication. |
| apps/…/trilium_server_facade.ts | Shows instance discovery, protocol checks, local/server choice, and API exchange. |
| apps/…/clipper.ts | Shows how Trilium turns clipper payloads into notes and attachments. |
| apps/…/routes.ts | Shows the public clipper API paths and their local-versus-server access rule. |
| apps/…/package.json | Shows the WXT version, lifecycle, browser-specific development/build/archive commands, and validation scripts. |
| apps/…/wxt.config.ts | Shows browser permissions, commands, development profiles, manifest differences, reproducible source archives, and archive naming. |
| .github/…/web-clipper.yml | Shows when browser archives are built and how release artifacts are published. |