[Repo Assist] feat: wire WebView2 bidirectional native↔SPA bridge in WebChatWindow#192
Conversation
Implements the WebView2 bridge proposed in issue #191. ## Changes ### OpenClaw.Shared — WebBridgeMessage - New `WebBridgeMessage` record: wire format `{"type":"...","payload":{...}}` - Well-known type constants: recording-start/stop, voice-start/stop, draft-text, ready - `TryParse(string?)` — null-safe parser, returns null on malformed input - `ToJson(object?)` — serialiser, optional runtime payload overrides stored one ### WebChatWindow.xaml.cs - Subscribe `CoreWebView2.WebMessageReceived` → fire `BridgeMessageReceived` event (SPA sends via `window.chrome.webview.postMessage({type, payload})`) - Add `PostBridgeMessage(string type, object? payload = null)` for native→SPA (SPA receives via `window.chrome.webview.addEventListener('message', ...)`) - Handler stored and unregistered in `OnWindowClosed` (no leak) - Uses existing `using OpenClaw.Shared;` import — no new dependencies ### Tests (+15) - `WebBridgeMessageTests`: parse valid/invalid/edge cases; ToJson; round-trip for all well-known types; payload override ## Test Status - `dotnet test OpenClaw.Shared.Tests` — **648 passed, 20 skipped** (↑15 from 633) - `dotnet test OpenClaw.Tray.Tests` — 122 passed (unchanged) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Thanks for picking up the Windows host side of the bridge from #191. I opened the matching SPA-side draft PR here: openclaw/openclaw#69633 That PR adds the |
…bchat-webview2-bridge-2026-04-21-f5724c21afd19b9c
Validate incoming WebView bridge origins, marshal native-to-SPA posts onto the WebView dispatcher, guard closed windows, and validate stored payload JSON before embedding it in bridge messages. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Implemented the Windows WebChat side of this proposal in #192 / c7630fa. Credit to @AlexAlves87 for the original WebView2 native ↔ SPA bridge proposal, the The merged implementation follows the core direction from this issue and adds Windows-side hardening around origin validation, dispatcher marshaling for WebView2 calls, closed-window guards, sanitized bridge logging, and payload JSON validation. |
🤖 This is an automated PR from Repo Assist.
Implements the Windows side of the WebView2 bridge proposed in issue #191.
What changed
OpenClaw.Shared—WebBridgeMessageNew
WebBridgeMessagerecord defining the bridge message contract:recording-start,recording-stop,voice-start,voice-stop,draft-text,readyTryParse(string?)— null-safe JSON parser, returnsnullon malformed inputToJson(object?)— serialiser; runtime payload overrides storedPayloadJsonWebChatWindow.xaml.csSPA → native (incoming messages):
The SPA sends via
window.chrome.webview.postMessage({ type, payload })—window.chrome.webviewis automatically available in WebView2-hosted pages.Native → SPA (outgoing messages):
The SPA receives via
window.chrome.webview.addEventListener('message', e => { const msg = e.data; ... }).Handler is stored in
_webMessageReceivedHandlerand unregistered inOnWindowClosed— no event-handler leak.Why this matters
From issue #191 — three open PRs need this infrastructure:
voice-start/voice-stopbridge messagesrecording-start/recording-stopdraft-textbridge messageWhat's NOT in scope
window.chrome.webview.addEventListenerin the gateway SPA (tracked in [Proposal] Add a formal WebView2 bridge for native ↔ SPA communication #191 as a separate repo concern)ExecuteScriptAsyncchannel; bridge upgrade can be a separate PRrecording-startfrom ScreenCapability is a follow-on once the SPA side is readyTest Status
dotnet test OpenClaw.Shared.Tests— 648 passed, 20 skipped (↑15 from 633; 15 newWebBridgeMessageTests)dotnet test OpenClaw.Tray.Tests— 122 passed (unchanged)