Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Environment:AI QL Tuui Electron Preload Process

From Leeroopedia
Knowledge Sources
Domains Electron, IPC, Security
Last Updated 2026-10-24 20:38 GMT

Overview

Context-isolated preload bridge environment that securely exposes whitelisted IPC channels between the Electron main and renderer processes.

Description

The preload process runs in an isolated context between the main and renderer processes. It uses contextBridge.exposeInMainWorld to expose a limited, whitelisted API surface to the renderer. The preload script exposes window.mainApi (send, on, once, off, removeListener, invoke with channel whitelisting), window.mcpServers (MCP server API with tools/prompts/resources methods), window.llmApis, window.popupApis, window.startupApis, and window.dxtManifest. All IPC channels are validated against a whitelist before forwarding.

Usage

Use this environment for code running in src/preload/. The preload script is the sole bridge between the renderer and main process — any new IPC channel must be whitelisted here.

System Requirements

Category Requirement Notes
OS macOS, Windows, or Linux Same as Electron
Runtime Electron preload context Has limited Node.js access via ipcRenderer

Dependencies

NPM Packages

  • `electron` >= 42.0.1 (for contextBridge, ipcRenderer)

Type Dependencies

  • @/types/mcp (MCPAPI, DXTAPI, McpMetadataDxt, ClientProfile, AsyncFunction)
  • @/types/llm (LlmConfig)
  • @/types/popup (PopupConfig)
  • @/types/startup (StartupConfig)

Credentials

No credentials required. The preload script does not handle secrets directly.

Quick Install

# Preload is bundled with electron; no separate install needed
npm install electron@^42.0.1

Code Evidence

Context bridge with channel whitelisting from `src/preload/index.ts:8-21`:

const mainAvailChannels: string[] = [
  'msgRequestAppInfo', 'msgRequestGetDxtUrl', 'msgOpenExternalLink',
  'msgOpenDxtFilePath', 'msgOpenPath', 'msgOpenFile',
  'msgFileTransferRequest', 'msgCommandSelectionResult',
  'msgGetApiToken', 'msgMcpServersInit', 'msgMcpServersStop',
  'msgWindowReload'
]

Channel validation from `src/preload/index.ts:38-49`:

send: (channel: string, ...data: any[]): void => {
  if (
    mainAvailChannels.includes(channel) ||
    rendererDynamicChannels.some((respChannel) => channel.startsWith(respChannel))
  ) {
    ipcRenderer.send.apply(null, [channel, ...data])
  } else {
    throw new Error(`Unknown ipc channel name: ${channel}`)
  }
}

Common Errors

Error Message Cause Solution
`Unknown ipc channel name: {channel}` Channel not in whitelist Add channel to mainAvailChannels or rendererAvailChannels
`window.mcpServers is undefined` Preload script failed to load Check preload path in BrowserWindow webPreferences

Compatibility Notes

  • Dynamic channels: msgSamplingTransferResult and msgElicitationTransferResult use startsWith matching to support UUID-suffixed response channels.
  • Development mode: IPC calls are logged to console when NODE_ENV === 'development'.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment