[Repo Assist] feat: wire WebView2 bidirectional native↔SPA bridge in WebChatWindow#192
Draft
github-actions[bot] wants to merge 1 commit intomasterfrom
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>
11 tasks
Contributor
|
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 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)