| description | How to turn a new Electron desktop app into an OpenCLI adapter |
|---|
This guide is the fast entry point for turning a new Electron desktop application into an OpenCLI adapter.
If you want the full background and deeper SOP, read:
Use this workflow when the target app:
- is built with Electron, or at least exposes a working Chrome DevTools Protocol (CDP) endpoint
- can be launched with
--remote-debugging-port=<port> - should be automated through its real UI instead of a public HTTP API
If the app is not Electron and does not expose CDP, use the native desktop automation pattern instead. See CLI-ifying Electron Applications.
Typical macOS check:
ls /Applications/AppName.app/Contents/Frameworks/Electron\ Framework.frameworkIf Electron is present, the next step is usually to launch the app with a debugging port.
/Applications/AppName.app/Contents/MacOS/AppName --remote-debugging-port=9222Then point OpenCLI at that CDP endpoint:
export OPENCLI_CDP_ENDPOINT="http://127.0.0.1:9222"For a new Electron adapter, implement these commands first in src/clis/<app>/:
status.ts— verify the app is reachable through CDPdump.ts— inspect DOM and snapshot structure before guessing selectorsread.ts— extract the visible context you actually needsend.ts— inject text and submit through the real editornew.ts— create a new session, tab, thread, or document
This is the standard baseline because it gives you:
- a connection check
- a reverse-engineering tool
- one read path
- one write path
- one session reset path
The full rationale and examples are in CLI-ifying Electron Applications.
Goal: prove CDP connectivity before touching app-specific logic.
Typical checks:
- current URL
- document title
- app shell presence
If status is unstable, stop there and fix connectivity first.
Do not guess selectors from the rendered UI.
Dump:
document.body.innerHTML- accessibility snapshot
- any stable attributes such as
data-testid,role,aria-*, framework-specific markers
Use the dump to identify real containers, buttons, composers, and conversation regions.
Target only the app region that matters.
Good targets:
- message list
- editor history
- visible thread content
- selected document panel
Avoid dumping the entire page text into the final command output.
Most Electron apps use React-style controlled editors, so direct .value = ... assignments are often ignored.
Prefer editor-aware input patterns such as:
- focus the editable region
- use
document.execCommand('insertText', false, text)when applicable - use real key presses like
Enter,Meta+Enter, or app-specific shortcuts
Many desktop apps rely on keyboard shortcuts for “new chat”, “new tab”, or “new note”.
Typical pattern:
const isMac = process.platform === 'darwin';
await page.pressKey(isMac ? 'Meta+N' : 'Control+N');
await page.wait(1);For a TypeScript desktop adapter, the usual layout is:
src/clis/<app>/status.ts
src/clis/<app>/dump.ts
src/clis/<app>/read.ts
src/clis/<app>/send.ts
src/clis/<app>/new.ts
src/clis/<app>/utils.ts
If the app grows beyond the baseline, add higher-level commands such as:
askhistorymodelscreenshotexport
When the adapter is ready, also add:
- an adapter doc under
docs/adapters/desktop/ - command list and examples
- launch instructions with
--remote-debugging-port - any required environment variables
- platform-specific caveats
Examples to study:
docs/adapters/desktop/codex.mddocs/adapters/desktop/chatwise.mddocs/adapters/desktop/notion.mddocs/adapters/desktop/discord.md
Usually one of these:
- the wrong window/tab is selected
- the app has not finished rendering
- selectors were guessed instead of discovered from
dump - the editor is controlled and ignores direct value assignment
Some desktop apps embed Chromium but do not expose a usable CDP surface. In that case, switch to the non-Electron desktop automation approach instead of forcing the Electron pattern.
If the app exposes a normal web URL and the browser flow is enough, a browser adapter is usually simpler. Use an Electron adapter only when the desktop app is the real integration surface.
If you are starting from zero:
- This page
- CLI-ifying Electron Applications
- Chrome DevTools Protocol
- TypeScript Adapter Guide
- One concrete desktop adapter doc under
docs/adapters/desktop/
Do not start with a large feature surface.
Start with:
statusdumpreadsendnew
Once those are stable, extend outward.