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
docs(skills): say which mobile requests stay in the page
Elian Dorancc1ff8fa573a
diff --git a/.claude/skills/developing-capacitor-mobile/SKILL.md b/.claude/skills/developing-capacitor-mobile/SKILL.mdindex 38630a3397..97a7def36c 100644--- a/.claude/skills/developing-capacitor-mobile/SKILL.md+++ b/.claude/skills/developing-capacitor-mobile/SKILL.md@@ -38,7 +38,7 @@ The client's `/api`, `/sync`, `/bootstrap`, `/search` requests (`LOCAL_API_PREFI**Most of them never leave the page.** The shell is a single WebView, so its one tab always wins the database lock, and a tab that owns the worker publishes `localFetch` on `window.standaloneApi`; the client's `ajax()` and `setupGlob()`'s `/bootstrap` call it directly rather than issuing a request (see the standalone skill, "Request flow" step 3). That covers everything routed through `apps/client/src/services/server.ts`, on both platforms alike.-What still leaves the page — engine-initiated loads (`<img src="api/images/…">`, `@font-face`, themes, media, iframes such as the PDF viewer), uploads, the LLM stream — goes to a **native request bridge** on both platforms; neither registers a service worker. The native side sees every request the engine issues, whichever subsystem issued it, and hands local API paths to the page: it calls `window.__triliumNativeRequest()`, `native-request-bridge.ts` answers from `localFetch()`, and the reply comes back as JSON strings: a `head`, the body in chunks, then `end`/`error`. Where the platforms differ is how the request is caught and how the body travels:+What still leaves the page — engine-initiated loads (`<img src="api/images/…">`, `@font-face`, themes, media, iframes such as the PDF viewer) — goes to a **native request bridge** on both platforms; neither registers a service worker. Uploads stay in the page too: `uploadForm()` and the editor's image upload adapter (`packages/ckeditor5/src/plugins/uploadimage.ts`, via `glob.getLocalUpload()`) hand the `File` to `standaloneApi.localUpload`. So does AI chat: on standalone `streamChatCompletion()` posts `llm-chat/stream-start` through `server.post` and receives the reply over the WebSocket channel, never the SSE route. The native side sees every request the engine issues, whichever subsystem issued it, and hands local API paths to the page: it calls `window.__triliumNativeRequest()`, `native-request-bridge.ts` answers from `localFetch()`, and the reply comes back as JSON strings: a `head`, the body in chunks, then `end`/`error`. Where the platforms differ is how the request is caught and how the body travels:- **Android** (`https://localhost`) — `TriliumWebViewClient.shouldInterceptRequest` hands local paths to **`TriliumRequestBridge.java`** (logic in `LocalRequestBroker`). Replies come over the injected `window.triliumRequestBridge` WebMessageListener, the body as ArrayBuffer frames (4-byte request id + bytes; base64 `chunk` messages on a WebView without ArrayBuffer messages). The IO thread blocks until the head arrives (270 s cap, as in `sw.ts`), then the body streams through a queue-backed `InputStream`. A WebView without `WEB_MESSAGE_LISTENER` never gets the object, so `installNativeRequestBridge()` returns false and the page falls back to the service worker.- **iOS** (`capacitor://localhost`, where WebKit refuses a service worker) — `ViewController.webView(with:configuration:)` re-types Capacitor's registered `WebViewAssetHandler` to **`TriliumAssetHandler`** with `object_setClass` (WebKit raises on registering a second handler for a scheme, and Capacitor's `loadView()` is not overridable), which hands local paths to **`TriliumRequestBridge.swift`**. Replies come over the `window.webkit.messageHandlers.triliumRequestBridge` script message handler, the body always in base64 chunks (script messages cannot carry ArrayBuffers). Nothing blocks: the `WKURLSchemeTask` is completed by `didReceive(response)`, `didReceive(data)` per chunk and `didFinish()`. A main-document request through the handler counts as a page start and fails whatever the previous page left unanswered.