Workflow
Creating and Interacting with a Webview Panel
Extension-contributed webview lifecycle: Cocoon requests panel, Mountain manages native webview, messages proxy back and forth.
Creating and Interacting with a Webview Panel
Details the full lifecycle of extension-contributed UI, from Cocoon requesting a panel to Mountain managing the native webview and proxying messages.
Lifecycle
Extension calls createWebviewPanel(viewType, title, viewColumn, options)
-> Cocoon WebviewPanelProvider.CreateWebviewPanel Effect
-> IpcProvider sends $createWebviewPanel gRPC to Mountain
-> Mountain generates unique handle (UUID)
-> Mountain creates WebviewStateDto, stores in AppState.ActiveWebviews
-> Mountain emits Tauri event: sky://webview/create
-> Mountain sends handle back to Cocoon as gRPC response
Cocoon:
-> Creates WebviewPanelShim and WebviewShim, stores handle
-> Returns WebviewPanelShim to extension
Wind/UI:
-> WebviewManagementService receives sky://webview/create
-> Dynamically creates TauriWebviewWindow or iframe, associates with handle
Extension sets content:
-> panel.webview.html = "<h1>Hello</h1>"
-> WebviewShim sends $setWebviewHtml gRPC to Mountain
-> Mountain emits sky://webview/set-html event
-> Wind sets inner HTML of webview element
-> User sees content
User interaction:
-> User clicks button in webview
-> vscode.postMessage({ command: 'doSomething' })
-> Wind sends TauriInvoke('mountain://webview/on-message')
-> Mountain looks up webview's owner sidecar
-> Mountain sends $onDidReceiveMessage gRPC to Cocoon
-> Cocoon WebviewPanelProvider fires onDidReceiveMessage event
-> Extension receives message payloadPhase 1: Extension Creates the Webview (Cocoon)
- Extension’s
activate()runs. Callswindow.createWebviewPanel(viewType, title, viewColumn, options). WebviewPanelProviderin Cocoon constructs a DTO with all panel options, extension ID, andlocalResourceRootslocation.- Sends
$createWebviewPanelgRPC request to Mountain, awaits a unique handle.
Phase 2: Host Creates the Native Webview (Mountain)
$createWebviewPanelrequest dispatched toWebviewProvidertrait.WebviewProvider.CreateWebviewPanel()generates a UUID handle, createsWebviewStateDto, stores inAppState.ActiveWebviews.- Emits
sky://webview/createTauri event to Sky frontend. - Sends the handle back to Cocoon as the gRPC response.
Phase 3: UI Renders the Webview (Wind/Sky)
WebviewManagementServicereceives thesky://webview/createevent.- Creates a new
TauriWebviewWindowor iframe within the main window’s DOM, associated with the handle.
Phase 4: Content and Interaction (Cocoon <-> Mountain <-> Wind)
- Cocoon creates
WebviewPanelShimandWebviewShimwith the handle, returns it to the extension. - Extension sets
panel.webview.html. The Shim sends$setWebviewHtmlgRPC to Mountain. - Mountain emits
sky://webview/set-htmlevent. Wind sets the inner HTML of the webview. - User clicks a button in the webview, calling
vscode.postMessage(). - Wind sends
TauriInvoke('mountain://webview/on-message', { Handle, Message }). - Mountain looks up the webview’s owner sidecar and sends
$onDidReceiveMessagegRPC to Cocoon. - Cocoon fires
onDidReceiveMessageevent. Extension receives the message payload.
Key Source Files
Mountain/Source/Environment/WebviewProvider.rs— webview creation and HTML managementCocoon/src/Service/WebviewPanel.ts— webview panel providerCocoon/src/Service/Ipc.ts— IPC provider
