Skip to content

packages/desktop dev mode crashes in browser - Tauri APIs called unconditionally #10160

@kyashrathore

Description

@kyashrathore

Description

The packages/desktop README documents a web-only development mode that doesn't actually work. The code calls Tauri APIs unconditionally without checking if running in a Tauri context, causing immediate crashes when running in a browser.

Documentation Claims

From packages/desktop/README.md (lines 16-20):

If you only want the web dev server (no native shell):

\`\`\`bash
bun run --cwd packages/desktop dev
\`\`\`

This suggests the desktop package supports browser-only development for quick iteration without the native shell overhead.

Actual Behavior

Running bun run --cwd packages/desktop dev and opening http://localhost:1420 in a browser results in multiple crashes:

Error 1: OS Type Detection

TypeError: Cannot read properties of undefined (reading 'os_type')
    at type (@tauri-apps_plugin-os.js:20:47)
    at index.tsx:47:18

Location: src/index.tsx:47 - calls ostype() unconditionally in createPlatform()

Error 2: Menu Creation

TypeError: Cannot read properties of undefined (reading 'os_type')
    at type (@tauri-apps_plugin-os.js:20:47)
    at createMenu (menu.ts:10:7)

Location: src/menu.ts:10 - calls ostype() without checking Tauri context

Error 3: WebView Zoom

TypeError: Cannot read properties of undefined (reading 'os_type')
    at type (@tauri-apps_plugin-os.js:20:47)
    at webview-zoom.ts:8:17

Location: src/webview-zoom.ts:8 - calls ostype() at module initialization

Error 4: Server Readiness Check

TypeError: Cannot read properties of undefined (reading 'invoke')
    at invoke (chunk-IT22SQDD.js:107:37)
    at ServerGate (index.tsx:324:45)

Location: src/index.tsx:324 - calls invoke("ensure_server_ready") unconditionally

Root Cause

The code assumes it's always running in a Tauri context and calls Tauri APIs directly without checking "__TAURI__" in window. This breaks the documented browser-only dev mode.

Files Affected

All these files call Tauri APIs unconditionally:

  1. src/index.tsx

    • ostype() - line ~47
    • invoke("ensure_server_ready") - line ~324
    • invoke("kill_sidecar") - multiple locations
    • invoke("get_default_server_url") - line ~315
    • invoke("set_default_server_url") - line ~320
    • invoke("parse_markdown_command") - line ~324
    • open(), save() - file picker dialogs
    • check() - updater
    • tauriFetch() - HTTP requests
    • isPermissionGranted(), requestPermission() - notifications
    • relaunch() - restart functionality
  2. src/menu.ts

    • ostype() - line 10
  3. src/webview-zoom.ts

    • ostype() - line 8
    • invoke("plugin:webview|set_webview_zoom") - line 27

Proposed Solutions

Option 1: Fix the Code (Recommended)

Add Tauri context detection and graceful fallbacks:

const isTauri = "__TAURI__" in window

// Example fixes:
const OS_NAME = isTauri ? ostype() : "unknown"

export async function createMenu() {
  if (!isTauri || ostype() !== "macos") return
  // ... rest of menu code
}

const [serverData] = createResource<ServerReadyData>(() => {
  if (!isTauri) {
    return Promise.resolve({ url: "http://127.0.0.1:4096", password: null })
  }
  return invoke("ensure_server_ready").then(...)
})

This would make the documented browser-only mode actually work.

Option 2: Update Documentation

If browser-only mode isn't intended to be supported, remove the misleading documentation:

- If you only want the web dev server (no native shell):
- 
- ```bash
- bun run --cwd packages/desktop dev
- ```

And clarify that tauri dev is the only supported development mode.

Impact

This affects developers who:

  • Don't have Tauri prerequisites installed
  • Want quick UI iteration without native shell overhead
  • Are following the documented workflow

Environment

  • Platform: macOS (but affects all platforms)
  • Node: v22.22.0
  • Bun: v1.3.6
  • Package: @opencode-ai/desktop v1.1.33

Additional Context

The web-only dev mode is a common pattern for Tauri/Electron apps to enable faster development iteration. The infrastructure (Vite dev server) is already in place - it just needs the Tauri API guards to make it work as documented.

Metadata

Metadata

Assignees

Labels

docswebRelates to opencode on web / desktop

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions