Skip to content

[web] Enable WebAssembly on latest Safari (Safari 26+)#186600

Draft
kevmoo wants to merge 1 commit into
flutter:masterfrom
kevmoo:i178893_allow_safari_latest_wasm
Draft

[web] Enable WebAssembly on latest Safari (Safari 26+)#186600
kevmoo wants to merge 1 commit into
flutter:masterfrom
kevmoo:i178893_allow_safari_latest_wasm

Conversation

@kevmoo

@kevmoo kevmoo commented May 16, 2026

Copy link
Copy Markdown
Contributor

Early implementations of WasmGC in Safari 18 syntactically validate WasmGC bytecode but crash at runtime during reference casting (WebKit Bug 295799). This change safely enables WebAssembly (both skwasm and dart2wasm + canvaskit) on Safari 26+ where WasmGC is fully stable, while ensuring older Safari builds defensively fall back to JavaScript (dart2js).

  • browser_environment.js: Added getWebKitVersion() to reliably extract major/minor WebKit versions across standalone Safari (macOS/iOS), iPad Desktop Mode, and WKWebViews (using iOS OS version as a surrogate). Updated supportsWasmGC() to enforce a minimum WebKit major version threshold of 26, and enabled defaultWasmSupport["webkit"] = true.
  • flutter.js: Exposed _supportsWasmGC on window._flutter to allow hermetic unit testing via Dart JS interop.
  • browser_environment_test.dart: Added hermetic unit tests mocking navigator.vendor and navigator.userAgent to verify version gating across all 5 WebKit UA permutations.
  • felt_config.yaml: Removed enable-ci: false from safari-dart2wasm-canvaskit-engine and safari-dart2wasm-skwasm-ui to re-enable automated CI testing.

Fixes #178893

Early implementations of WasmGC in Safari 18 syntactically validate WasmGC bytecode but crash at runtime during reference casting (WebKit Bug 295799). This change safely enables WebAssembly (both skwasm and dart2wasm + canvaskit) on Safari 26+ where WasmGC is fully stable, while ensuring older Safari builds defensively fall back to JavaScript (dart2js).

* browser_environment.js: Added getWebKitVersion() to reliably extract major/minor WebKit versions across standalone Safari (macOS/iOS), iPad Desktop Mode, and WKWebViews (using iOS OS version as a surrogate). Updated supportsWasmGC() to enforce a minimum WebKit major version threshold of 26, and enabled defaultWasmSupport["webkit"] = true.
* flutter.js: Exposed _supportsWasmGC on window._flutter to allow hermetic unit testing via Dart JS interop.
* browser_environment_test.dart: Added hermetic unit tests mocking navigator.vendor and navigator.userAgent to verify version gating across all 5 WebKit UA permutations.
* felt_config.yaml: Removed enable-ci: false from safari-dart2wasm-canvaskit-engine and safari-dart2wasm-skwasm-ui to re-enable automated CI testing.

Fixes flutter#178893
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 16, 2026
@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. platform-web Web applications specifically labels May 16, 2026
Comment on lines +33 to +50
const getWebKitVersion = () => {
const ua = navigator.userAgent;
const versionMatch = ua.match(/Version\/(\d+)(?:\.(\d+))?/);
if (versionMatch) {
return {
major: parseInt(versionMatch[1], 10),
minor: parseInt(versionMatch[2] || "0", 10),
};
}
const iosMatch = ua.match(/(?:CPU iPhone OS|CPU OS) (\d+)(?:_(\d+))?/);
if (iosMatch) {
return {
major: parseInt(iosMatch[1], 10),
minor: parseInt(iosMatch[2] || "0", 10),
};
}
return null;
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of detecting the version, can we land this: #183835 which will take care of filtering out older versions of Safari that don't support built-in strings?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding: it's MORE than just the built-in strings. They have a crash that got fixed.

I guess it's possible that the fixes I want for their crashing behavior align w/ the strings stuff. We'd just have to research that FIRST!

But it's much better to feature detection than version parsing. Agreed!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We stopped seeing the crash around this release: https://developer.apple.com/documentation/safari-technology-preview-release-notes/stp-release-228

It has two changes that look relevant:

  1. Added support for Wasm Memory buffer APIs.
  2. Added support for Wasm JS String Builtins.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we didn't need a FEATURE for this. It was a bug fix.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BUT! If they happen to align, GREAT! The bug is EASY to reproduce if you run dart2wasm in Safari for more than 5 seconds. I'll take the feature detection version!

Comment on lines +80 to +85
if (getBrowserEngine() === "webkit") {
const version = getWebKitVersion();
if (!version || version.major < 26) {
return false;
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we still want to go with a version check, this should move up before the WebAssembly.validate() call. Reason: the version check is faster.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do!

@MarlonJD

Copy link
Copy Markdown
Contributor

Update: #188797 has landed and #188723 is closed, resolving the Safari canvas-sizing issue I was tracking here.
What would be the most useful next step to move Safari Wasm enablement forward? Is #183835 still the intended feature-detection path, or should this PR proceed with the Safari 26 version gate? I’m happy to help with the implementation and run the Safari validation once the direction is agreed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD engine flutter/engine related. See also e: labels. platform-web Web applications specifically

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[web] Enable WebAssembly for latest Safari [Safari 26.0.1]

4 participants