DorkOS
Integrations

Updating an extension for its own frame

What changed in version 2 of the extension API, and what to change in your extension

Updating an extension for its own frame

Each extension's screens now run in a frame of their own, walled off from the DorkOS page. The frame cannot read your sign-in, call DorkOS directly, or touch the rest of the app. Everything your extension does goes through the api object DorkOS hands it, and DorkOS checks each call against the extension that made it.

This is version 2 of the extension API. There is no compatibility mode: an extension that has not been updated shows "This app needs an update for this version of DorkOS" in Settings, with a link here, and does not load.

1. Say you support version 2

Add one line to extension.json:

{
  "id": "my-extension",
  "name": "My Extension",
  "version": "1.1.0",
  "clientApiVersion": 2
}

2. Call your own server through api.request

The frame has no network access, so fetch fails. Call your server half with api.request instead, and declare it in the manifest:

{
  "capabilities": { "http": true }
}
// Before
const res = await fetch('/api/ext/my-extension/status');
const status = await res.json();

// After
const status = await api.request<Status>('/status');
await api.request('/items', { method: 'POST', body: { title: 'New item' } });

The path is relative to your own routes (/api/ext/my-extension/). DorkOS encodes each part of it for you. A part may contain . and : (/reports/q3.v2:final), but a part that is . or .., an empty part (//), a backslash, a raw % and a full address are refused. Put values that need encoding in the query (/search?q=…), which DorkOS re-encodes.

The reply comes back as JSON, as text, or as null for no content. When your route answers with an error, the promise rejects with its status and body, so you can tell the cases apart. No reply headers reach your code.

try {
  await api.request('/items/42', { method: 'DELETE' });
} catch (error) {
  const { status, body } = error as { status?: number; body?: unknown };
  if (status === 409) showConflict(body);
}

To read your extension's settings, use api.settings.get() instead of fetching /api/extensions/my-extension/settings.

3. Drop what the frame no longer has

  • executeCommand is gone. Use api.navigate to move the person to a page.
  • openCanvas now goes through DorkOS, which checks what you send. See Putting things on the canvas.
  • <img src> and <video src> pointing at a web address do not load in the frame. Fetch the file with api.media; see Showing pictures and video.
  • <a download> does not work in the frame. Use api.download; see Saving a file.
  • document.cookie, localStorage, sessionStorage and window.parent are not available. Keep data with api.saveData and api.loadData.
  • window.electronAPI is gone. Its only use was getServerPort(), to build an address for fetch; api.request replaces that, and works the same on the web, the desktop app and the phone.
  • Imports are limited to react, react-dom, react-dom/client, react/jsx-runtime and @dorkos/extension-api. Bundle anything else into your extension. React is still a global.

4. Expect activate to run more than once

DorkOS calls activate once to learn what your extension adds (its pages, panels, commands and settings tabs), then once more inside each screen it shows. api.context tells you which:

export function activate(api: FrameExtensionAPI) {
  api.registerPage('', Dashboard, { title: 'My Extension' });

  // One-time work belongs to the registration run only.
  if (api.context === 'registration') {
    void api.loadData().then(migrateOldData);
  }
}

Type against FrameExtensionAPI from @dorkos/extension-api to get the version 2 surface, including context, request and settings.

5. Check functions you receive

Props DorkOS passes your components still arrive as values and functions. A function crosses the frame as a message, so calling it works, but it returns nothing to your code. when and visibleWhen options on a component still work, and run inside your frame. An icon component cannot cross the frame, so a right-panel tab shows the default puzzle-piece icon; a command's icon stays a string, as before.

Putting things on the canvas

api.openCanvas still puts a document beside the chat, but DorkOS checks what you send and opens it for you:

await api.openCanvas({ type: 'browser', url: 'http://localhost:5173/', title: 'Preview' });
await api.openCanvas({ type: 'markdown', content: '# Weekly report', title: 'Report' });

You may open Markdown, JSON, a widget, a picture (data: or https:) or a web page (http: or https:). Files, PDFs, diffs, local paths and MCP apps are refused. A widget's buttons may only link to a web page (url): a widget with an agent, ui or emit action is refused, because those act for the person. What you open is always a new tab, never one already showing. The tab shows the app icon and the title, and says "Opened by" with your app's name as DorkOS knows it. Nothing on the canvas sends messages back to your app.

Calling another app

One app can call another app's server routes, but only when both say so in their manifests.

The app that calls lists the exact apps it calls:

{ "capabilities": { "http": { "apps": ["ledger"] } } }

The app it calls lists each route other apps may use. Nothing is shared unless it is listed here. A read is a GET; each write needs its own method in methods. callers narrows a route to named apps. A route in personOnly only answers the app's own screens, and is never shared, whatever http says:

{
  "exports": {
    "http": [
      { "path": "/entries", "methods": ["GET"] },
      { "path": "/entries/:id", "methods": ["GET", "PATCH"], "callers": ["reports"] },
      { "path": "/approvals", "methods": ["GET"] }
    ],
    "personOnly": ["/approve", { "path": "/approvals", "methods": ["POST"] }]
  }
}

A plain path in personOnly covers every method there. A path with methods covers only those, so other apps can read /approvals while only your own screens can post to it. An export and a personOnly rule may not name the same method on paths that can match the same address; DorkOS refuses that manifest when you install it.

Then call it with app:

const entries = await api.request('/entries', { app: 'ledger' });

The card that asks a person to allow your app lists each app it uses, by DorkOS's name for it, what that app shares with yours ("reads", or "reads and changes"), and, for an app you list with "navigate": true, "can open its pages" ("can only open its pages" when it shares nothing). An app that shares nothing with yours and that you don't open is left off the card, since it gives your app no power. An update that lists a new app asks the person again; one that drops an app does not.

:id stands for exactly one path segment. Listing an app works one way only: it gives that app nothing back. DorkOS checks both manifests in the window and again on the server, tells the other app which app called in the X-DorkOS-Caller-App header, and records every call in the audit log. A refused call rejects before anything is sent.

Opening another app's page

To send the person to another app's pages, list that app as an entry with "navigate": true. A plain id only lets you call its routes. You can mix both kinds in one list, and each app goes in once:

{ "capabilities": { "http": { "apps": ["ledger", { "id": "mkt-newsletter", "navigate": true }] } } }

The other app does not need to export anything: a page only shows what the person can already open.

const result = await api.navigate('/x/ledger/item/entry/e-17');
if (!result.ok) api.notify(result.message, { type: 'error' });

The address names the item and nothing else: no query, no #, no encoded characters like %2F, and at most 8 parts after the app's id. So a link can say which item, never what to do with it. The page the person lands on decides what happens, and should change nothing until the person clicks.

Call it from a click or key press in your app, such as a button's onClick. DorkOS opens the page only when the person just clicked or typed inside your app's own frame. A click in another app, or a call from a timer or on load, is refused with no-gesture. One click opens one page: a second navigate on the same click is refused too. For half a second after the page opens, DorkOS ignores clicks and keys while the new page fades in, so a click meant for your app can't land on the other one.

navigate never throws for an address it refuses. It answers { ok: false, reason, message }, where reason is one of:

reasonWhat it means
not-declaredYour app does not list that app with "navigate": true.
target-unavailableThat app is not installed or not turned on.
not-an-item-pathThe address carries a query, a #, an encoded character or too many parts.
unknown-routeDorkOS has no page at that address.
no-gestureIt was not called right after a click or key press in your app.

Your own pages and DorkOS's own pages work as before, query included.

Showing pictures and video

The frame cannot reach the network, so a picture or video has to come through DorkOS. Serve it from your own server routes, then ask for it:

const blob = await api.media('/covers/q3.png');
const src = URL.createObjectURL(blob);
// <img src={src} alt="Q3 cover" />. Call URL.revokeObjectURL(src) when it leaves the screen.

api.media needs capabilities.http, and follows the same path rule as api.request. It takes PNG, JPEG, WebP, GIF, AVIF, MP4 and WebM, up to 32 MB. Your route must send the right Content-Type; DorkOS types the file from it. SVG is refused, because an SVG file can carry script. A failed reply rejects with its status and body, like api.request.

Long video

api.media reads the whole file before it shows anything, so it suits pictures and short clips. For a long video, ask for a link instead and give it to <video src>:

const src = await api.mediaUrl('/videos/intro.mp4');
// <video src={src} controls />

The browser then loads the video in pieces as it plays, so it starts quickly, you can skip ahead, and there is no size limit. A few things to know:

  • api.mediaUrl needs capabilities.http, and your server half needs a fetch handler or "runtime": "subprocess". An app with only an Express router can't stream video this way.
  • The path is a plain path inside your app: no query, no #, no empty part, no . or .., and no encoded characters such as %2F.
  • Your route must answer video/mp4 or video/webm. It gets only the Range and If-Range headers, and is told its caller is not a person, so requirePerson() refuses it. Answer 206 Partial Content for a range request if you can. Other statuses, redirects and other types are refused.
  • The link is for your app's frame. Anyone holding it can play that one video, so never show it as text or post it in a chat or room. It lasts 10 minutes after it was last used and 2 hours at most. Your app keeps 16 links at a time. Turning your app off, reloading it or updating it ends every link, so ask again when a video stops loading.

Saving a file

A link with download does nothing inside the frame. Ask DorkOS instead:

const answer = await api.download('people-export.json', 'application/json', JSON.stringify(rows));
// 'saved' or 'cancelled'

DorkOS shows its own dialog, "People wants to save a file", with the name and size, and saves the file only when the person chooses Save. The file is always saved as a plain download, never opened. You may save JSON, plain text, CSV, Markdown, PDF, PNG, JPEG and WebP, up to 10 MB, one at a time. DorkOS reduces the name to a bare filename, and refuses names that run or install when opened (.sh, .exe, .app, .html, .svg and the like). A refused file rejects the promise and shows the person nothing.

Screen data is its own store

api.saveData and api.loadData in your screens keep up to 512 KB of JSON in a store of their own. It is separate from ctx.storage in your server half, which your screens can no longer read or overwrite. Data your screens saved before version 2 shared a file with ctx.storage, so it does not carry over: read what you need in your server half and hand it to your screens through a route.

Shipping a pre-built index.js

If your app ships index.js instead of index.ts, DorkOS serves that file as it is, as a plain script in the frame, not as a module. It must assign its exports to __dorkosExtension, and load React and the SDK with require. An ES-module bundle (export function activate) does not load. With esbuild:

esbuild index.tsx --bundle --format=iife --global-name=__dorkosExtension \
  --external:react --external:react-dom --external:@dorkos/extension-api --outfile=index.js

An app that ships index.ts needs none of this: DorkOS builds it this way for you.

What stays the same

Registering pages, panels, Activity sections, status-bar items, commands, dialogs and settings tabs; getState and subscribe; api.events; api.rooms; api.forward; decisions and per-project settings; notify, navigate, setTabMarker and setPageBadge. Your server half does not change at all.

Your screens pick up DorkOS's styles, light or dark mode, font choice and the text size of the place they sit in, like the status bar's smaller text, and follow them when the person changes them.