[web] Enable WebAssembly on latest Safari (Safari 26+)#186600
Conversation
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
| 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; | ||
| }; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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:
- Added support for Wasm Memory buffer APIs.
- Added support for Wasm JS String Builtins.
There was a problem hiding this comment.
Yeah, we didn't need a FEATURE for this. It was a bug fix.
There was a problem hiding this comment.
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!
| if (getBrowserEngine() === "webkit") { | ||
| const version = getWebKitVersion(); | ||
| if (!version || version.major < 26) { | ||
| return false; | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
|
Update: #188797 has landed and #188723 is closed, resolving the Safari canvas-sizing issue I was tracking here. |
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).
Fixes #178893