feat: Replace CefSharp with Microsoft Edge WebView2 - #276
Open
CyberCriminal0 wants to merge 1 commit into
Open
Conversation
The Syncthing UI was hosted in CefSharp.Wpf's ChromiumWebBrowser, which uses CEF's windowless (off-screen) rendering mode. Every frame was rasterised on the CPU, copied in full into a MemoryMappedFile on the CEF UI thread, marshalled to the WPF dispatcher, copied a second time into a WriteableBitmap, and only then uploaded to the GPU. CEF also caps windowless rendering at 30fps by default, and forces GPU compositing off, so the page was rasterised entirely by Skia on the CPU. At 1920x1080 that is 8.3MB per frame for the first copy alone. On a high-DPI display it is considerably worse, and the second copy happens on the UI thread, so the whole application stutters along with it. WebView2 hosts a real child window and composites on the GPU, so none of those copies happen at all. Notable details: - The zoom level is still stored in configuration on CEF's logarithmic scale, so existing config files keep working. It is converted to WebView2's linear ZoomFactor on use. - The JavaScript bridge for "open folder" and "browse for folder" now uses postMessage/WebMessageReceived rather than a registered host object. - WebView2 hosts a native child window, which paints over WPF content in the same grid cell, so the browser is collapsed while the "Syncthing starting/stopped" messages are showing. - The Intel Xe graphics warning is removed: it existed because CEF's off-screen rendering misbehaved on those drivers. The "disable hardware rendering" setting remains and still applies to SyncTrayzor's own WPF interface. - The CEF cache lockfile check is removed. WebView2 allows several processes to share a user data folder, so a second SyncTrayzor instance is no longer a problem. - Cache-disabling and the stripping of If-None-Match/If-Modified-Since headers are dropped. These worked around CEF-specific behaviour; Syncthing serves its assets with correct cache validators. The browser's data now lives in data\webview2 (portable) or %LOCALAPPDATA%\SyncTrayzor\webview2 (installed). SyncTrayzor now requires the Microsoft Edge WebView2 Runtime, which ships with Windows 11 and reaches Windows 10 via Microsoft Edge. If it is missing, SyncTrayzor offers a link to the download page and carries on running Syncthing normally.
Owner
|
Hi, thanks for the contribution. I don't have time to review this today, so it'll likely have to wait another week, but I'll take a look when I can! |
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.
Closes #179
This work originated from some stuttering issues I had running this software on a high DPI monitor, the CEF webui appeared to render the Syncthing UI at a much lower framerate than my own monitor and with some infrequent graphical artifacts. Testing with Windows 11's native WebView2 resolves issues like this and likely would provide the same functionality without the external CEF dependency. WebView2 is native to Windows 11 and ships to Windows 10 via Edge.
The Syncthing UI was hosted in CefSharp.Wpf's ChromiumWebBrowser, which uses CEF's windowless (off-screen) rendering mode. Every frame was rasterised on the CPU, copied in full into a MemoryMappedFile on the CEF UI thread, marshalled to the WPF dispatcher, copied a second time into a WriteableBitmap, and only then uploaded to the GPU. CEF also caps windowless rendering at 30fps by default, and forces GPU compositing off, so the page was rasterised entirely by Skia on the CPU.
At 1920x1080 that is 8.3MB per frame for the first copy alone. On a high-DPI display it is considerably worse, and the second copy happens on the UI thread, so the whole application stutters along with it.
WebView2 hosts a real child window and composites on the GPU, so none of those copies happen at all.
Notable details:
The browser's data now lives in data\webview2 (portable) or %LOCALAPPDATA%\SyncTrayzor\webview2 (installed).
SyncTrayzor now requires the Microsoft Edge WebView2 Runtime, which ships with Windows 11 and reaches Windows 10 via Microsoft Edge. If it is missing, SyncTrayzor offers a link to the download page and carries on running Syncthing normally.
Testing:
task test — 58/58 passing.
Builds clean for win-x64; no new warnings.