const demoVideoUrl = 'https://github.com/user-attachments/assets/d1601b54-2669-45d7-b1e5-9bbde1186856' import { DynamicCodeBlock } from 'fumadocs-ui/components/dynamic-codeblock' import { gitConfig } from '@/lib/shared' import { Link } from 'waku' const codeCards = { shared: [ "import { defineProxy } from 'comctx'", "import { streamText } from 'ai'", "import { openai } from '@ai-sdk/openai'", '', 'class AiService {', ' async translate(text: string, targetLanguage: string) {', ' const result = await streamText({', " model: openai('gpt-4o-mini'),", ' prompt: `Translate to ${targetLanguage}:\\n${text}`', ' })', '', ' return result.textStream', ' }', '}', '', 'export const [provideAi, injectAi] = defineProxy(() => new AiService(), {', " namespace: '__worker-transfer-example__',", ' transfer: true', '})' ], main: [ "import Adapter from './adapter'", "import { injectAi } from './service'", '', 'const ai = injectAi(new Adapter())', '', "const stream = await ai.translate('Hello world', 'zh-CN')", '', 'for await (const chunk of stream) {', ' console.log(chunk)', '}' ], worker: [ "import Adapter from './adapter'", "import { provideAi } from './service'", '', 'const ai = provideAi(new Adapter())' ] } as const const darkCodeOptions = { themes: { light: 'github-dark', dark: 'github-dark' } } as const const features = [ { title: 'Environment Agnostic', description: 'Works across Web Workers, browser extensions, iframes, Electron, and more.' }, { title: 'Bidirectional Communication', description: 'Supports method calls and callbacks across the boundary.' }, { title: 'Zero Copy', description: 'Automatically extracts and transfers transferable objects when enabled.' }, { title: 'Type Safety', description: 'Keeps the same typed API on both provider and injector sides.' }, { title: 'Lightweight', description: 'Ships a small core without forcing a runtime-specific transport.' }, { title: 'Fault Tolerance', description: 'Supports backup implementations and connection heartbeat checks.' } ] export default function Home() { return (
JavaScript cross-context RPC

Comctx

Use RPC to communicate easily across contexts in any JavaScript environment.

Web Workers Extensions iframes Electron Message-based runtimes
Read the docs Star on GitHub

Worker RPC flow

Demo

Real-world browser extension RPC.

Features

Core capabilities.

{features.map((item) => (
Feature
{item.title}

{item.description}

))}
) } export async function getConfig() { return { render: 'static' } }