Skip to content

engine: warn on WASM load failure when not crossOriginIsolated#186252

Merged
auto-submit[bot] merged 6 commits into
flutter:masterfrom
shivanshu877:feat/142822-wasm-coop-coep-warning-v2
Jul 8, 2026
Merged

engine: warn on WASM load failure when not crossOriginIsolated#186252
auto-submit[bot] merged 6 commits into
flutter:masterfrom
shivanshu877:feat/142822-wasm-coop-coep-warning-v2

Conversation

@shivanshu877

Copy link
Copy Markdown
Contributor

Description

Fixes #142822.

When a Flutter WASM web app fails to load because the host page isn't cross-origin isolated (no COOP/COEP headers), the underlying WebAssembly errors are obscure and don't point at the actual problem. Examples users currently see:

  • ReferenceError: SharedArrayBuffer is not defined
  • RuntimeError: WebAssembly.instantiate(): shared memory not enabled
  • TypeError: Failed to execute 'compileStreaming' on 'WebAssembly'

This PR wraps the WASM entrypoint load in _loadWasmEntrypoint in a try/catch. On failure, it checks window.crossOriginIsolated === false. When that's the case, it emits a single console.warn that:

  • Names the two missing HTTP headers (Cross-Origin-Opener-Policy: same-origin and Cross-Origin-Embedder-Policy: require-corp).
  • Suggests building with the JavaScript compile target instead of dart2wasm if the developer can't change the server headers.
  • Links to the canonical web.dev COOP/COEP guide.

The original error is re-thrown — the existing failure path is unchanged. This is purely additive diagnostic output.

Tests

No JS test infrastructure exists for engine/src/flutter/lib/web_ui/flutter_js/. The change is also diagnostic-only — it doesn't alter runtime behavior beyond the new console.warn. Requesting a test exemption.

This PR replaces #186236 (closed for a clean conversation timeline).

Pre-launch Checklist

When a Flutter WASM web app fails to load because the hosting page is
not cross-origin isolated (i.e. the server isn't sending COOP/COEP
HTTP headers), the underlying WebAssembly / SharedArrayBuffer errors
that surface in the browser console are obscure and don't point the
developer at the real problem.

Wrap the WASM entrypoint load in a try/catch and, on failure, check
window.crossOriginIsolated === false. When that's the case, emit a
single console.warn that names the missing headers
(Cross-Origin-Opener-Policy: same-origin and
Cross-Origin-Embedder-Policy: require-corp), suggests building for
JavaScript instead if the headers can't be set, and links to the
canonical web.dev guide. The original error is re-thrown so the
existing failure path is unchanged.

Fixes flutter#142822
@flutter-dashboard

Copy link
Copy Markdown

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. platform-web Web applications specifically labels May 8, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request introduces a try-catch block around the Flutter Web WASM loading logic to provide a descriptive warning when the hosting page lacks cross-origin isolation. This helps developers identify configuration issues related to COOP and COEP headers. Feedback suggests using Promise.all when awaiting multiple promises to improve robustness and intent clarity.

Comment thread engine/src/flutter/lib/web_ui/flutter_js/src/entrypoint_loader.js Outdated
@gaaclarke gaaclarke added the team-web Owned by Web platform team label May 11, 2026
@flutter-zl
flutter-zl requested a review from mdebbar May 13, 2026 18:13
@mdebbar

mdebbar commented May 13, 2026

Copy link
Copy Markdown
Contributor

Thanks for the contribution! Printing a warning is a good idea, but there is a better place to do it.

There've been many changes since that issue was filed. The code doesn't fail anymore when not crossOriginIsolated. Instead, we detect it and switch to single-threaded mode:

skwasmSingleThreaded: config.enableWimp || !browserEnvironment.crossOriginIsolated || browserEnvironment.isChromeExtension || config.forceSingleThreadedSkwasm,

My suggestion is instead of doing a try-catch, you could use the values of browserEnvironment.crossOriginIsolated and config.forceSingleThreadedSkwasm to decide when to print the warning.

@mdebbar mdebbar added the waiting for response The Flutter team cannot make further progress on this issue until the original reporter responds label May 13, 2026
Per @mdebbar's review feedback: the system now auto-detects missing
cross-origin isolation and switches to single-threaded mode rather than
failing, so the warning belongs in skwasm_loader.js where that fallback
decision is made — not in a try/catch in entrypoint_loader.js.

Changes:
- Revert try/catch wrapper from _loadWasmEntrypoint in entrypoint_loader.js
- Add console.warn in skwasm_loader.js when !browserEnvironment.crossOriginIsolated
  && !config.forceSingleThreadedSkwasm, immediately before skwasm.default() is
  called with skwasmSingleThreaded: true
@github-actions github-actions Bot removed team-web Owned by Web platform team waiting for response The Flutter team cannot make further progress on this issue until the original reporter responds labels May 14, 2026
@shivanshu877

Copy link
Copy Markdown
Contributor Author

Thanks @mdebbar — you're right that skwasm_loader.js was the better place for this. Pushed commit a737602 that:

  • Reverts the try/catch from _loadWasmEntrypoint in entrypoint_loader.js (back to its original shape).
  • Adds a console.warn in skwasm_loader.js immediately before skwasm.default(), gated on !browserEnvironment.crossOriginIsolated && !config.forceSingleThreadedSkwasm. This way the warning fires on the success path (multithreaded skwasm is being downgraded to single-threaded), not in an error catch.

Message text names the two missing headers, suggests single-threaded mode is the fallback, and links to https://web.dev/articles/coop-coep. Ready for re-review when you have a moment.

@gaaclarke gaaclarke added the team-web Owned by Web platform team label May 18, 2026
@gaaclarke

Copy link
Copy Markdown
Member

hey @mdebbar, I noticed there is a bot removing team-web is that expected?

@flutter-zl
flutter-zl requested a review from harryterkelsen May 27, 2026 18:29

@harryterkelsen harryterkelsen left a comment

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 mentioning the SharedArrayBuffer, I think this warning message should say something like "Skwasm uses multi-threading and web workers for better performance, but your page needs to be cross-origin isolated to support multi-threading."

Also, please make it configurable to suppress this warning.

Per harryterkelsen's review on flutter#186252:

* Reword the warning to describe what skwasm actually loses (multi-threading
  / web workers for performance) rather than the underlying mechanism
  (SharedArrayBuffer).
* Add a `suppressMultithreadingWarning` config flag so apps that are aware
  of the constraint and cannot enable cross-origin isolation (browser
  extensions, embedded environments, etc.) can silence the warning without
  also being forced into single-threaded mode via forceSingleThreadedSkwasm.
* Mention the new flag in the warning text so devs reading the warning
  know how to opt out.
* Add the new field to FlutterConfiguration in types.d.ts.
@shivanshu877

Copy link
Copy Markdown
Contributor Author

Reworded per your wording suggestion and added a suppressMultithreadingWarning config flag (separate from forceSingleThreadedSkwasm so apps can silence the warning without also opting out of multi-threading where it's available). Let me know if you'd also like a Dart-side mirror in configuration.dart or a test.

@github-actions github-actions Bot removed the team-web Owned by Web platform team label May 30, 2026
@mdebbar
mdebbar requested a review from harryterkelsen June 1, 2026 19:43
@mdebbar mdebbar added the CICD Run CI/CD label Jun 1, 2026
@mdebbar

mdebbar commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

hey @mdebbar, I noticed there is a bot removing team-web is that expected?

I haven't noticed that. Let me dig into it!

@harryterkelsen harryterkelsen left a comment

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.

LGTM

@harryterkelsen harryterkelsen added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 1, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 1, 2026
@auto-submit

auto-submit Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/186252, because The base commit of the PR is older than 7 days and can not be merged. Please merge the latest changes from the main into this branch and resubmit the PR.

@github-actions github-actions Bot added the CICD Run CI/CD label Jun 24, 2026
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Jul 7, 2026
@harryterkelsen harryterkelsen added CICD Run CI/CD autosubmit Merge PR when tree becomes green via auto submit App labels Jul 7, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jul 7, 2026
@auto-submit

auto-submit Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/186252, because - The status or check suite Mac mac_host_engine has failed. Please fix the issues identified (or deflake) before re-applying this label.

@harryterkelsen harryterkelsen added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 7, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jul 7, 2026
@auto-submit

auto-submit Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/186252, because - The status or check suite Mac mac_host_engine has failed. Please fix the issues identified (or deflake) before re-applying this label.

@harryterkelsen harryterkelsen added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 7, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Jul 8, 2026
Merged via the queue into flutter:master with commit 7cab22b Jul 8, 2026
217 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jul 8, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Jul 10, 2026
…12169)

Manual roll Flutter from 91939cc4db78 to dc2a8703e12b (50 revisions)

Manual roll requested by [email protected]

flutter/flutter@91939cc...dc2a870

2026-07-09 [email protected] [ios,macos] Update swiftc.py flags to match swiftc (flutter/flutter#189174)
2026-07-09 [email protected] [AGP 9] Update Warn Version to AGP 9+ (flutter/flutter#189109)
2026-07-09 [email protected] Sync CHANGELOG.md from stable (flutter/flutter#189203)
2026-07-09 [email protected] [web] Roll Chrome to 145 (framework) (flutter/flutter#182861)
2026-07-09 [email protected] Roll Packages from 52d84d6 to 20928d5 (6 revisions) (flutter/flutter#189194)
2026-07-09 [email protected] [web] Avoid absolute positioning for base CanvasKit canvas (flutter/flutter#188337)
2026-07-09 [email protected] Roll Dart SDK from cdb7217e65aa to a11fb7ed40a5 (6 revisions) (flutter/flutter#189195)
2026-07-09 [email protected] Fix dereference of nullptr in the moved-to-rect signal in the Linux embedder (flutter/flutter#189152)
2026-07-09 [email protected] Fix data for design packages (flutter/flutter#189140)
2026-07-09 [email protected] Roll Skia from 7b42d1251d54 to ab3a7b98c94d (2 revisions) (flutter/flutter#189181)
2026-07-09 [email protected] Roll Skia from 05d9d214e0b7 to 7b42d1251d54 (2 revisions) (flutter/flutter#189175)
2026-07-09 [email protected] Roll Skia from 542c8bdd7f4f to 05d9d214e0b7 (4 revisions) (flutter/flutter#189169)
2026-07-09 [email protected] UberSDF rect handling for thin (line-like) rectangles (flutter/flutter#188821)
2026-07-09 [email protected] Roll Skia from dd572c07f63c to 542c8bdd7f4f (4 revisions) (flutter/flutter#189160)
2026-07-09 [email protected] [flutter_tools] Fix hot restart for WASM web builds (flutter/flutter#187898)
2026-07-08 [email protected] Split FlViewRenderer into OpenGL and software backends (flutter/flutter#188824)
2026-07-08 [email protected] Promote android_hardware_smoke_tests out of bringup in CI (flutter/flutter#189081)
2026-07-08 [email protected] Roll Skia from 8df24be66531 to dd572c07f63c (4 revisions) (flutter/flutter#189150)
2026-07-08 [email protected] Expose LinuxWindowRegistrar on _window_linux.dart in order to better support out of tree LinuxWindowingOwners (flutter/flutter#188917)
2026-07-08 [email protected] Roll pub packages (flutter/flutter#189149)
2026-07-08 [email protected] fix(ci): harden some workflows (flutter/flutter#189087)
2026-07-08 [email protected] Roll Skia from 51a62da33da0 to 8df24be66531 (1 revision) (flutter/flutter#189139)
2026-07-08 [email protected] Roll Dart SDK to Dart 3.13 beta3 (flutter/flutter#189122)
2026-07-08 [email protected] [flutter_tools] Don't crash on non-UTF-8 plugin pubspec.yaml (flutter/flutter#188976)
2026-07-08 [email protected] [flutter_tools] Watch transitive #include headers for FragmentProgram hot reload (flutter/flutter#187945)
2026-07-08 [email protected] Roll Skia from 040d9f55de00 to 51a62da33da0 (1 revision) (flutter/flutter#189135)
2026-07-08 [email protected] Roll Packages from 92525f5 to 52d84d6 (7 revisions) (flutter/flutter#189134)
2026-07-08 [email protected] [flutter_tools] Forcefully kill hung subprocesses 5 seconds after timeout (flutter/flutter#187178)
2026-07-08 [email protected] Expose the app's build name and number as compile-time constants (flutter/flutter#187935)
2026-07-08 [email protected] Roll Skia from 1ff92f879815 to 040d9f55de00 (1 revision) (flutter/flutter#189131)
2026-07-08 [email protected] Roll Skia from 6137414bef5c to 1ff92f879815 (6 revisions) (flutter/flutter#189126)
2026-07-08 [email protected] [test cross imports] More test/rendering + flutter_test/test fixes (flutter/flutter#188954)
2026-07-08 [email protected] engine: explain why each candidate build was skipped in Flutter web loader (flutter/flutter#186254)
2026-07-08 [email protected] vscode: add missing unicode.h (flutter/flutter#189102)
2026-07-08 [email protected] Roll Fuchsia Linux SDK from 7RjQJBW3m-3Jl-7jr... to QcRFUtvCw2EobfJ8s... (flutter/flutter#189104)
2026-07-08 [email protected] Roll Skia from 075fbe4778d9 to 6137414bef5c (10 revisions) (flutter/flutter#189106)
2026-07-08 [email protected] engine: warn on WASM load failure when not crossOriginIsolated (flutter/flutter#186252)
2026-07-08 [email protected] Roll Dart SDK from c9bccc09e733 to db2155f56bf3 (2 revisions) (flutter/flutter#189105)
2026-07-08 [email protected] [flutter_tools] Prevent interactive device selection in machine mode (flutter/flutter#188267)
2026-07-08 [email protected] [flutter_tools] Fix wireless ADB device discovery when serial contains spaces (flutter/flutter#187943)
2026-07-07 [email protected] [web] Fix grouped autofill on iOS Chrome (flutter/flutter#187459)
2026-07-07 [email protected] Fix TextSelectionOverlay crash when layout is degenerate (flutter/flutter#188672)
2026-07-07 [email protected] [flutter_tools] Provision Android NDK in the main Gradle invocation (flutter/flutter#186337)
2026-07-07 [email protected] Android_hardware_smoke_test: Migrate to AGP 9 (flutter/flutter#189082)
...
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 team-web Owned by Web platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Web+wasm load logic should console.warn if wasm load failure is due to COOP/COEP

5 participants