Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/slic3r/GUI/PrinterWebView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
24 changes: 24 additions & 0 deletions src/slic3r/GUI/Widgets/WebView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions src/slic3r/GUI/Widgets/WebView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down