Skip to content

osra

Connect two JavaScript contexts over any message channel — functions, streams, errors, and abort signals cross live, with zero runtime dependencies and full type-safety.

osra is a zero-runtime-dependency TypeScript RPC library that connects two JavaScript contexts over any message channel. Both sides call expose(value, { transport }) and each receives the other’s value with live semantics: functions become callable async proxies, async generators stream with for await, errors keep their subclasses, AbortSignals propagate aborts. It works across Workers, SharedWorkers, windows/iframes, MessagePorts, WebSockets, web extensions, and anything else you can wrap in a custom { emit, receive } pair.

Symmetric API

Both sides call expose() — there is no separate client/server entry point. Either side can pass functions, both can call, and each returned promise resolves with the peer’s value once the handshake completes.

Deep type support

Functions, promises, async generators, ReadableStream/WritableStream, MessagePort, AbortSignal, Error subclasses, Map/Set, typed arrays, BigInt, and more cross the boundary live. See supported types.

Works over any channel

Workers, windows and iframes, WebSockets, web extensions, or any custom { emit, receive } pair — degrading gracefully to a JSON-only mode on text transports. See transports.

Strict TypeScript

Remote<T> maps your API type across the wire; a compile-time Capable check rejects non-serializable values with the offending path pinpointed. See the TypeScript reference.