Skip to content

Messaging

The bridge messaging API lets your web app send commands to the IDE host and receive responses back.

Sends a fire-and-forget message to the IDE extension host. No reply is expected.

import { bridge } from '@unextension/bridge'
bridge.postMessage('openFile', { path: 'src/index.ts' })
bridge.postMessage('ping') // no payload needed
ParameterTypeRequiredDescription
typestringThe message type / command name
payloadunknownOptional data to send along with the message

Sends a message to the IDE host and returns a Promise that resolves with the reply. Uses a correlationId to match the reply to the request.

import { bridge } from '@unextension/bridge'
const files = await bridge.request<string[]>('list-project-files', { pattern: '**/*.ts' })

This is the foundation all built-in actions are built on. Use it to implement custom actions.

ParameterTypeRequiredDescription
typestringThe message type / command name
payloadunknownOptional data to send

Promise<T> — resolves with the payload field of the type:reply message.


Registers a handler for messages sent from the IDE host to the web app.

import { bridge } from '@unextension/bridge'
const unsubscribe = bridge.onMessage((message) => {
console.log('Message from IDE:', message)
})
// Later — stop listening
unsubscribe()
ParameterTypeDescription
handler(message: unknown) => voidCalled whenever a message is received from the host

Returns an unsubscribe function — call it to remove the handler.


IDEUnderlying mechanism
VS CodeacquireVsCodeApi().postMessage / window.onmessage
JetBrainswindow.__unextension_jb_bridge / window.onmessage
Neitherlogs a warning (useful during browser development)

import { useEffect } from 'react'
import { bridge } from '@unextension/bridge'
function MyView() {
useEffect(() => {
const unsub = bridge.onMessage((msg) => {
console.log('Got:', msg)
})
return unsub // cleanup on unmount
}, [])
return (
<button onClick={() => bridge.postMessage('hello', { from: 'MyView' })}>
Say hello to IDE
</button>
)
}