Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(web-clipper): look for a dev desktop on the port it runs on
Elian Doran0e662108770e
diff --git a/.claude/skills/developing-web-clipper/SKILL.md b/.claude/skills/developing-web-clipper/SKILL.mdindex 94aa5968bf..d283a665bb 100644--- a/.claude/skills/developing-web-clipper/SKILL.md+++ b/.claude/skills/developing-web-clipper/SKILL.md@@ -44,7 +44,7 @@ pages or the extension stores, where no content script runs.## Finding and authenticating to Trilium- **Desktop first.** `getPort()` returns the port from the options page, or **37840** (production)- / **37742** (development build). It tries that one port — there is no port scan — with+ / **37743** (development build, the port `pnpm desktop:start` uses). It tries that one port — there is no port scan — with`GET http://127.0.0.1:<port>/api/clipper/handshake`, then falls back to the configured server.It repeats every 60 seconds, and on the popup's **check** button.- **Version check.** The handshake returns `protocolVersion` (`CLIPPER_PROTOCOL_VERSION` in@@ -57,8 +57,8 @@ pages or the extension stores, where no content script runs.- **Server routes** are in `apps/server/src/routes/routes.ts` (`/api/clipper/*`) with the handlersin `apps/server/src/routes/api/clipper.ts` (spec: `clipper.spec.ts`). They are **server-only**, notin `packages/trilium-core`, so the standalone and mobile builds cannot receive clippings.-- The desktop dev script (`apps/desktop/package.json`) currently runs on **37743**, so a dev build of- the clipper does not find a dev desktop without setting the port in its options.+- The dev port must match `TRILIUM_PORT` in `apps/desktop/package.json`'s `dev` script; when one+ changes, change `getPort()` and the Developer Guide's *Web Clipper* page with it.## Compatibility: the extension outlives the server versiondiff --git a/apps/web-clipper/entrypoints/background/trilium_server_facade.spec.ts b/apps/web-clipper/entrypoints/background/trilium_server_facade.spec.tsindex 38714c4b8f..16091faa47 100644--- a/apps/web-clipper/entrypoints/background/trilium_server_facade.spec.ts+++ b/apps/web-clipper/entrypoints/background/trilium_server_facade.spec.ts@@ -36,10 +36,10 @@ describe("TriliumServerFacade", () => {await createFacade();- expect(fetchMock).toHaveBeenCalledWith("http://127.0.0.1:37742/api/clipper/handshake");+ expect(fetchMock).toHaveBeenCalledWith("http://127.0.0.1:37743/api/clipper/handshake");expect(searchStatuses()).toEqual([{ status: "searching" },- { status: "found-desktop", port: 37742, url: "http://127.0.0.1:37742" }+ { status: "found-desktop", port: 37743, url: "http://127.0.0.1:37743" }]);});@@ -173,7 +173,7 @@ describe("TriliumServerFacade", () => {fetchMock.mockResolvedValue(notFound);await expect(openNote()).rejects.toThrow(requestFailed("Note 'abc' not found"));expect(fetchMock).toHaveBeenLastCalledWith(- "http://127.0.0.1:37742/api/clipper/open/abc",+ "http://127.0.0.1:37743/api/clipper/open/abc",expect.objectContaining({headers: expect.objectContaining({ Authorization: "" })}));@@ -238,7 +238,7 @@ describe("TriliumServerFacade", () => {fetchMock.mockResolvedValue(Response.json({ noteId: "n1" }));await facade.triggerSearchNoteByUrl("https://example.com/a?b=c");expect(fetchMock).toHaveBeenLastCalledWith(- "http://127.0.0.1:37742/api/clipper/notes-by-url/https%3A%2F%2Fexample.com%2Fa%3Fb%3Dc",+ "http://127.0.0.1:37743/api/clipper/notes-by-url/https%3A%2F%2Fexample.com%2Fa%3Fb%3Dc",expect.objectContaining({ method: "GET" }));expect(sendMessage).toHaveBeenLastCalledWith({name: "trilium-previously-visited",diff --git a/apps/web-clipper/entrypoints/background/trilium_server_facade.ts b/apps/web-clipper/entrypoints/background/trilium_server_facade.tsindex 74da9190d0..f642e835ef 100644--- a/apps/web-clipper/entrypoints/background/trilium_server_facade.ts+++ b/apps/web-clipper/entrypoints/background/trilium_server_facade.ts@@ -210,7 +210,7 @@ export default class TriliumServerFacade {return parseInt(triliumDesktopPort, 10);}- return import.meta.env.DEV ? 37742 : 37840;+ return import.meta.env.DEV ? 37743 : 37840;}async callService(method: string, path: string, body?: string | object) {diff --git a/docs/Developer Guide/Developer Guide/Concepts/Web Clipper.md b/docs/Developer Guide/Developer Guide/Concepts/Web Clipper.mdindex dc504658ea..503bba6420 100644--- a/docs/Developer Guide/Developer Guide/Concepts/Web Clipper.md+++ b/docs/Developer Guide/Developer Guide/Concepts/Web Clipper.md@@ -27,7 +27,7 @@ This will open a separate browser instance in which the extension is automaticalThe default port is:-* `37742` if in development mode. This makes it possible to use `pnpm desktop:start` to spin up a desktop instance to use the Clipper with.+* `37743` if in development mode, the port `pnpm desktop:start` runs the desktop app on, so a dev build of the Clipper finds a dev desktop instance.* `37840` in production, the default Trilium port.## Building