Skip to content

Bridge API

The @unextension/bridge package is the core of unextension — it provides a unified API for your web app to communicate bidirectionally with the IDE extension host, regardless of whether it runs inside VS Code or JetBrains.

Terminal window
npm install @unextension/bridge
# or
pnpm add @unextension/bridge

Your web app runs inside a WebView. The bridge abstracts the different messaging APIs each IDE provides:

IDEUnderlying mechanism
VS CodeacquireVsCodeApi().postMessage / window.onmessage
JetBrainswindow.__unextension_jb_bridge / window.onmessage

You never need to think about which IDE you’re in — just use the bridge.

import { bridge } from '@unextension/bridge'
// Send a message to the extension host
bridge.postMessage('openFile', { path: 'src/index.ts' })
// Listen for messages from the extension host
const unsubscribe = bridge.onMessage((message) => {
console.log('Received from IDE:', message)
})
// Stop listening when done
unsubscribe()
  • MessagingpostMessage, onMessage and request
  • Actions — built-in actions: listProjectFiles, runCommand, notify, readProjectFile, writeProjectFile, runScript
  • Scripts — writing and bundling Node.js scripts for runScript
  • Types — TypeScript interfaces and types