From 621ed87b6acb1bb4b35b0fc9137d9ab10e899062 Mon Sep 17 00:00:00 2001 From: KaputterKerl Date: Wed, 18 Nov 2026 00:18:12 +0100 Subject: [PATCH] fix(linux): make Flutter web pages take the Chromium path under WebKitGTK Flutter web chooses its browser-specific code path from navigator.vendor. Under WebKitGTK it takes the WebKit path, where checkbox state is presented one frame late: the checkbox that was clicked last only updates on the next pointer event. On the login page ("Remember me", "I have read and agree") and in Print Preprocessing (Time-lapse, Auto Leveling, Extrusion flow calibration) checkmarks seem to disappear on hover or to affect each other. Reproduced with plain WebKitGTK 2.54.1 and 2.50.6 and the standalone Snapmaker Control pages; the same pages are fine in a desktop browser. The Windows build already sends a Chromium user agent and therefore takes the Blink path. A Chromium-style user agent alone is not enough on Linux, navigator.vendor has to be changed as well, so add a user script (scoped to /web/flutter_web/ pages) that reports a Chromium vendor and user agent. Measured with synthetic pointer input: 8 checkpoints of clicking and hovering both login checkboxes, 5 wrong without the script, 0 wrong with it. --- src/slic3r/GUI/PrinterWebView.cpp | 1 + src/slic3r/GUI/Widgets/WebView.cpp | 24 ++++++++++++++++++++++++ src/slic3r/GUI/Widgets/WebView.hpp | 2 ++ 3 files changed, 27 insertions(+) diff --git a/src/slic3r/GUI/PrinterWebView.cpp b/src/slic3r/GUI/PrinterWebView.cpp index 3891ffe2f567..14e752c13251 100644 --- a/src/slic3r/GUI/PrinterWebView.cpp +++ b/src/slic3r/GUI/PrinterWebView.cpp @@ -193,6 +193,7 @@ void PrinterWebView::SendAPIKey() // AddUserScript works correctly on these platforms (Edge WebView2, WebKitGTK). // Do NOT call Reload() — the current page is already handled by RunScript above. m_browser->RemoveAllUserScripts(); + WebView::AddFlutterCompatScript(m_browser); m_browser->AddUserScript(script); #endif } diff --git a/src/slic3r/GUI/Widgets/WebView.cpp b/src/slic3r/GUI/Widgets/WebView.cpp index b278018d096f..35fdc8f8ddd8 100644 --- a/src/slic3r/GUI/Widgets/WebView.cpp +++ b/src/slic3r/GUI/Widgets/WebView.cpp @@ -612,6 +612,7 @@ wxWebView* WebView::CreateWebView(wxWindow * parent, wxString const & url) webView->SetUserAgent(wxString::Format("SM-Slicer/v%s (%s) Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko)", SLIC3R_VERSION, Slic3r::GUI::wxGetApp().dark_mode() ? "dark" : "light")); #endif + WebView::AddFlutterCompatScript(webView); #ifdef __WXMAC__ WKWebView * wkWebView = (WKWebView *) webView->GetNativeBackend(); Slic3r::GUI::WKWebView_setTransparentBackground(wkWebView); @@ -689,6 +690,29 @@ void WebView::LoadUrl(wxWebView * webView, wxString const &url) webView->LoadURL(url2); } +void WebView::AddFlutterCompatScript(wxWebView *webView) +{ +#if defined(__linux__) + // Flutter web picks its browser-specific code path from navigator.vendor. Under WebKitGTK the + // WebKit path presents checkbox state one frame late: the last-clicked checkbox only updates on + // the next pointer event, so checkmarks seem to vanish or to affect each other (login page, + // Print Preprocessing). Windows already reports a Chromium user agent and uses the Blink path, + // so make the Flutter pages see the same on Linux. Scoped to the bundled Flutter pages. + webView->AddUserScript(wxString::FromUTF8( + "(function(){" + "if(location.href.indexOf('/web/flutter_web/')<0)return;" + "try{" + "Object.defineProperty(navigator,'vendor',{get:function(){return 'Google Inc.';}});" + "var ua='Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36';" + "Object.defineProperty(navigator,'userAgent',{get:function(){return ua;}});" + "Object.defineProperty(navigator,'appVersion',{get:function(){return ua.substring(8);}});" + "}catch(e){}" + "})();")); +#else + (void) webView; +#endif +} + bool WebView::RunScript(wxWebView *webView, wxString const &javascript) { if (Slic3r::GUI::wxGetApp().app_config->get("internal_developer_mode") == "true" diff --git a/src/slic3r/GUI/Widgets/WebView.hpp b/src/slic3r/GUI/Widgets/WebView.hpp index 5879afffe932..abdc4b424023 100644 --- a/src/slic3r/GUI/Widgets/WebView.hpp +++ b/src/slic3r/GUI/Widgets/WebView.hpp @@ -14,6 +14,8 @@ class WebView static void LoadUrl(wxWebView * webView, wxString const &url); static bool RunScript(wxWebView * webView, wxString const & msg); + // Linux only (no-op elsewhere): make the bundled Flutter pages take Flutter's Chromium code path under WebKitGTK. + static void AddFlutterCompatScript(wxWebView * webView); static void RecreateAll(); };