Skip to content

fix(linux): make Flutter web pages take the Chromium path under WebKitGTK - #1212

Open
KaputterKerl wants to merge 1 commit into
Snapmaker:mainfrom
KaputterKerl:fix/linux-flutter-webview-vendor
Open

KaputterKerl wants to merge 1 commit into
Snapmaker:mainfrom
KaputterKerl:fix/linux-flutter-webview-vendor

Conversation

@KaputterKerl

Copy link
Copy Markdown

Description

Fix checkboxes in the bundled Flutter web pages (login, Print Preprocessing) that show a stale state under WebKitGTK on Linux.

Symptom: On the login page ("Remember me", "I have read and agree") and in Print Preprocessing ("Time-lapse camera", "Auto leveling", "Extrusion flow calibration"), the checkbox that was clicked last does not update until the next pointer event. Checkmarks seem to disappear when the pointer moves to another element, or the two checkboxes seem to affect each other.

Cause: Flutter web chooses its browser-specific code path from navigator.vendor (see K() in flutter_bootstrap.js). WebKitGTK reports Apple Computer, Inc., so Flutter takes its WebKit path, where the new checkbox state is presented one frame late. The same pages are fine in a desktop browser and on Windows, where the slicer already sends a Chromium user agent (... Chrome/107 ... Edg/107) and Flutter takes the Blink path.

A Chromium-style user agent alone is not enough on Linux (tested with Edg/ in the UA, still 5 of 8 checkpoints wrong); navigator.vendor has to be changed as well, and WebKitGTK has no setting for that.

Change:

  • WebView::AddFlutterCompatScript() adds a user script on Linux that reports navigator.vendor = "Google Inc." and a Chromium user agent. The script returns immediately unless the page URL contains /web/flutter_web/, so other pages are unaffected. On other platforms the function does nothing.
  • It is called when a web view is created, and again in PrinterWebView::SendAPIKey() right after RemoveAllUserScripts() so the script is not lost there.

Caveat: This is a workaround on the slicer side. Flutter now assumes a Chromium environment on Linux. I only checked the pages below. The better long-term fix is on the web UI side or in WebKit. The checkbox behaviour is also reproducible with plain WebKitGTK 2.54.1 and 2.50.6.

Screenshots/Recordings/Graphs

Not applicable (state of the checkboxes after each click, measured from screenshots, see Tests).

Tests

Environment: Fedora 44 (Nobara), Wayland, NVIDIA RTX 2070 SUPER (620.70), system webkit2gtk4.1 2.54.1, built as AppImage from main (2.4.2) with this change (plus #1081 and #1205 so that the canvas renders on NVIDIA).

  • Standalone Snapmaker Control 1.10.0 pages in a small GTK test window with plain WebKitGTK 2.54.1, synthetic GTK pointer input, 8 checkpoints (click "Remember me", click "agree", click both again, hover the Log In button, leave): 5 of 8 wrong without the script, 0 of 8 wrong with it (two runs each).
  • Same test in a WebKitGTK 2.50.6 runtime: same wrong behaviour without the script.
  • Running slicer (AppImage with this change): login and Print Preprocessing checkboxes update immediately and keep their state; Home, Device, My Devices load normally.

Not tested: Windows and macOS (the new function is a no-op there), Flatpak build.

…tGTK

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant