Skip to content

fix(webview): enable WebGL on OffscreenCanvas in WebKitGTK views - #269

Closed
zackees wants to merge 2 commits into
mainfrom
fix/offscreen-canvas-webgl-main
Closed

zackees wants to merge 2 commits into
mainfrom
fix/offscreen-canvas-webgl-main

Conversation

@zackees

@zackees zackees commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator

Summary

Port of #268 (which targets release/0.1.3 for v0.1.4) to main.

WebKitGTK ships its AllowWebGLInWorkers runtime feature disabled. Despite the name, it gates WebGL on every OffscreenCanvas, including canvases a document creates, so new OffscreenCanvas(1, 1).getContext('webgl2') returns null in Linux webviews. Chromium, Firefox and Safari 17+ expose these contexts by default. This blocked FastLED's viewer (FastLED/cli#247).

The Linux adapter now enables the feature on each new view's settings before its first navigation. The WebKitGTK 2.42+ feature API is resolved at run time with dlsym(RTLD_DEFAULT), because the published webkit2gtk bindings stop at 2.40 and linking the symbols directly would stop older hosts from loading. The change is private to src/tauri/linux_webkitgtk.rs plus one call in src/tauri.rs; the smoke scenario is re-applied by hand because main's smoke binary has diverged from the release branch.

Evidence

Check Result
New offscreen-webgl smoke scenario, facade call disabled (RED) webgl2=0, fails
Same scenario with the fix (GREEN) passes
Existing smoke scenarios: close, bootstrap, redirect, timeout, cancel, window-close, capture, capture-cancel, open-cancel pass
Unit tests in tauri::linux_webkitgtk (including the new display-free enable + read-back test) 4 passed
cargo clippy --features tauri-webview-test-support --all-targets -D warnings, cargo fmt --check pass

Smoke runs used the CI lane's environment (Xvfb, software GL, compositing disabled, WebKitGTK 2.52.5). The scenario is added to the tauri-webview-smoke CI job. main currently has failing CI jobs unrelated to this change, so compare this PR's checks against the base branch's runs.

Known limitation (not addressed here)

With the feature enabled, WebKitGTK 2.52 still lets only the first thread to create a WebGL context succeed. On NVIDIA 595.99.02 under Wayland, a document WebGL2 context followed by worker rendering crashes the web process in NVIDIA EGL during GL context teardown; this reproduces in stock MiniBrowser and is tracked in FastLED/cli#247 for an upstream report.

Refs #268, FastLED/cli#247.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VfXV1EpgAvMZzXJfbGZPRG

WebKitGTK ships its AllowWebGLInWorkers runtime feature disabled. That feature
gates WebGL on every OffscreenCanvas, including canvases a document creates,
so pages that probe or render through OffscreenCanvas get no WebGL context in
Linux webviews. Chromium, Firefox and Safari 17+ enable these contexts by
default.

The Linux adapter now enables the feature on each view's settings before its
first navigation. The WebKitGTK 2.42+ feature API is resolved at run time from
the loaded library, because the published bindings stop at 2.40 and a direct
link would stop older hosts from loading. Those hosts keep the engine default.

Tests:
- Unit test enables the feature on a display-free WebKitSettings object and
  reads it back.
- New offscreen-webgl smoke scenario (added to the Xvfb CI lane) reports
  webgl2=0 with the facade call disabled and passes with it enabled.

Port of #268 to main.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01VfXV1EpgAvMZzXJfbGZPRG
Creating a WebKitSettings object initializes GTK style and settings state,
which aborts the whole test binary when no display connection exists. The
rust-native job runs `cargo test --all-features` without a display, so the
test is now ignored there and run explicitly with `--ignored` in the
tauri-webview-smoke job under xvfb-run.

Reproduced locally by hiding every display and the default Wayland socket:
the test binary segfaulted in GTK style-provider assertions. With the
attribute, the headless run reports the test as ignored and the Xvfb run
passes it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01VfXV1EpgAvMZzXJfbGZPRG
@zackees

zackees commented Sep 15, 2026 •

Copy link
Copy Markdown
Collaborator Author

CI note: the failing checks on this PR are pre-existing on main.

This PR's run (34914809661, head 0b047b9) has 14 failing and 1 cancelled job. I compared them with main's CI for this PR's base commit a13ff44 (run 34896877675):

  • Every job that fails or is cancelled here also fails on the base run: native compiler cache (6 targets), native screenshot (6 targets), threaded-rust-artifact (ubuntu, windows) and rust-native (windows-latest). No job fails only on this PR.
  • rust-native (windows-latest) fails on both runs at the strict Clippy step, with the same three errors in Windows-only files this PR doesn't touch:
    • src\platform_win\ipc_private_dir.rs:35:1: empty line after doc comment
    • src\platform_win\ipc_private_dir.rs:949:9: clippy::obfuscated_if_else
    • src\platform_win_cmdline.rs:55:36: clippy::unnecessary_cast

The jobs that exercise this change pass: tauri-webview-smoke (including the new offscreen-webgl scenario and the --ignored WebKitSettings test under Xvfb) and rust-native (ubuntu-latest).

The same fix is merged to release/0.1.3 as #268 and released as kernal-api v0.1.4. I'm leaving this PR open rather than merging it into a red main.

@zackees

zackees commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator Author

Closing without merging. Forcing WebKitGTK's AllowWebGLInWorkers freezes the FastLED viewer on NVIDIA Wayland: the web process crashes with a Skia GrResourceCache SIGILL (5 of 8 runs froze, versus 0 of 10 with the WebKitGTK default and main-thread rendering). The same toggle is being reverted on release/0.1.3; see the revert PR against that branch. My earlier CI note here stands, but the change itself should not land on main.

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