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.
Installation
Section titled “Installation”npm install @unextension/bridge# orpnpm add @unextension/bridgeHow it works
Section titled “How it works”Your web app runs inside a WebView. The bridge abstracts the different messaging APIs each IDE provides:
| IDE | Underlying mechanism |
|---|---|
| VS Code | acquireVsCodeApi().postMessage / window.onmessage |
| JetBrains | window.__unextension_jb_bridge / window.onmessage |
You never need to think about which IDE you’re in — just use the bridge.
Quick example
Section titled “Quick example”import { bridge } from '@unextension/bridge'
// Send a message to the extension hostbridge.postMessage('openFile', { path: 'src/index.ts' })
// Listen for messages from the extension hostconst unsubscribe = bridge.onMessage((message) => { console.log('Received from IDE:', message)})
// Stop listening when doneunsubscribe()