Skip to content

Running a .NET WebAssembly Browser App with multithreading enabled does not set the required COOP and COEP headers for the worker script #112040

@danroth27

Description

@danroth27

When I try to run a .NET WebAssembly Browser App with multithreading enabled, the runtime doesn't start because the required COOP and COEP headers are not set for the worker script:

Image'

Repro steps:

  1. Install the .NET 9 SDK
  2. Install the wasm-experimental workload: dotnet workload install wasm-experimental
  3. Create a new .NET WebAssembly Browser App: dotnet new wasmbrowser -o WasmBrowserApp
  4. Run the app and load in the browser: dotnet run - ✅ the stopwatch counter runs fine
  5. Update WasmBrowserApp.csproj to enable multithreading: <WasmEnableThreads>true</WasmEnableThreads>
  6. Run the app again and reload in the browser - ❌ the stopwatch counter never starts, as if the runtime didn't load

There are no errors in the browser console, but if you check the browser issues tab you should see the following security error:

Image

To work around the issue you can publish the app and then serve it using dotnet serve with the correct headers: dotnet serve -h "Cross-Origin-Opener-Policy:same-origin" -h "Cross-Origin-Embedder-Policy:require-corp" --directory .\bin\Release\net9.0\publish\wwwroot

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions