From 0a336941f4ef6d6b7e46de63c4b5e7c98fbb8557 Mon Sep 17 00:00:00 2001 From: HanifKoh <76276251+HanifKoh@users.noreply.github.com> Date: Wed, 14 Oct 2026 19:03:53 +0800 Subject: [PATCH] Restore the Tagged User-Agent on Linux with WebKitGTK's Own Prefix (#16466) Linux webviews lost the BBL-Slicer, dark|light and BBL-Language tags with the stock WebKitGTK User-Agent, so the bundled pages stayed light and dropped every message to the host. The tags come back on Linux, now appended to the string WebKitGTK reports for itself instead of the Mac one. Windows and macOS are untouched. --- src/slic3r/GUI/Widgets/WebView.cpp | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/Widgets/WebView.cpp b/src/slic3r/GUI/Widgets/WebView.cpp index d102aff2ef..b8c54aace1 100644 --- a/src/slic3r/GUI/Widgets/WebView.cpp +++ b/src/slic3r/GUI/Widgets/WebView.cpp @@ -56,7 +56,12 @@ namespace fs = boost::filesystem; #define WEBKIT_API struct WebKitWebView; struct WebKitJavascriptResult; +struct WebKitSettings; extern "C" { +WEBKIT_API WebKitSettings * +webkit_settings_new (void); +WEBKIT_API const gchar * +webkit_settings_get_user_agent (WebKitSettings *settings); WEBKIT_API void webkit_web_view_run_javascript (WebKitWebView *web_view, const gchar *script, @@ -284,6 +289,23 @@ static WebViewRef *webview_ref(wxWebView *webView) return webView ? static_cast(webView->GetRefData()) : nullptr; } +#ifdef __linux__ +// WebKitGTK's own User-Agent with the tags the bundled pages (globalapi.js) and Bambu's cloud read +// appended. wx's GTK backend cannot report the stock string, so it comes from a throwaway settings object. +static wxString linux_user_agent() +{ + static const wxString stock = [] { + WebKitSettings *settings = webkit_settings_new(); + wxString ua = wxString::FromUTF8(webkit_settings_get_user_agent(settings)); + g_object_unref(settings); + return ua; + }(); + return wxString::Format("%s BBL-Slicer/v%s (%s) BBL-Language/%s", stock, Slic3r::GUI::wxGetApp().get_bbl_client_version(), + Slic3r::GUI::wxGetApp().dark_mode() ? "dark" : "light", + Slic3r::GUI::wxGetApp().current_language_code().BeforeFirst('_')); +} +#endif + wxWebView* WebView::CreateWebView(wxWindow * parent, wxString const & url) { #if wxUSE_WEBVIEW_EDGE @@ -336,7 +358,9 @@ wxWebView* WebView::CreateWebView(wxWindow * parent, wxString const & url) s_schemes_registered = true; } webView->Create(parent, wxID_ANY, url2, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE); -#ifndef __linux__ +#ifdef __linux__ + webView->SetUserAgent(linux_user_agent()); +#else webView->SetUserAgent(wxString::Format("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) BBL-Slicer/v%s (%s) BBL-Language/%s", Slic3r::GUI::wxGetApp().get_bbl_client_version(), Slic3r::GUI::wxGetApp().dark_mode() ? "dark" : "light", language_code.mb_str())); #endif @@ -472,7 +496,9 @@ void WebView::RecreateAll() wxString language_code = Slic3r::GUI::wxGetApp().current_language_code().BeforeFirst('_'); language_code = language_code.ToStdString(); for (auto webView : g_webviews) { -#ifndef __linux__ +#ifdef __linux__ + webView->SetUserAgent(linux_user_agent()); +#else webView->SetUserAgent(wxString::Format("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) BBL-Slicer/v%s (%s) BBL-Language/%s", Slic3r::GUI::wxGetApp().get_bbl_client_version(), dark ? "dark" : "light", language_code.mb_str())); #endif