Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Howto configure the wasm runtime in Blazor projects in net8.0 #93475

Merged
merged 2 commits into from
Oct 13, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions docs/workflow/debugging/mono/wasm-debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,87 @@ C @ blazor.webassembly.js:1
dispatchGlobalEventToAllElements @ blazor.webassembly.js:1
onGlobalEvent @ blazor.webassembly.js:1
```

# Enabling additional logging in Blazor

In .NET 8+, Blazor startup can be controlled by setting the `autostart="false"` attribute on the
`<script>` tag that loads the blazor webassembly framework. After that, a call to the
`globalThis.Blazor.start()` JavaScript function can be passed additional configuration options,
including setting mono environment variables, or additional command line arguments.

The name of the script and the location of the `<script>` tag depends on whether the project was a
Blazor WebAssembly project (template `blazorwasm`) or a Blazor project (template `blazor`).

See the runtime `DotnetHostBuilder` interface in
[dotnet.d.ts](../../../../src/mono/wasm/runtime/dotnet.d.ts) for additional configuration functions.

## Blazor WebAssembly

In a `blazorwasm` project, the script is `_framework/blazor.webassembly.js` and it is loaded in `wwwroot/index.html`:

```html
<body>
<div id="app">
...
</div>

<div id="blazor-error-ui">
...
</div>
<script src="_framework/blazor.webassembly.js"></script>
</body>
```

Replace it with this:

```html
<body>
<div id="app">
...
</div>

<div id="blazor-error-ui">
...
</div>
<script src="_framework/blazor.webassembly.js" autostart="false"></script>

<script>
Blazor.start({
configureRuntime: dotnet => {
dotnet.withEnvironmentVariable("MONO_LOG_LEVEL", "debug");
dotnet.withEnvironmentVariable("MONO_LOG_MASK", "all");
}
});
</script></body>
```

## Blazor
maraf marked this conversation as resolved.
Show resolved Hide resolved

In a `blazor` project, the script is `_framework/blazor.web.js` and it is loaded by `Components/App.razor` in the server-side project:

```html
<body>
<Routes />
<script src="_framework/blazor.web.js"></script>
</body>
```

Replace it with this:

```html
<body>
<Routes />
<script src="_framework/blazor.web.js" autostart="false"></script>
<script>
Blazor.start({
webAssembly: {
configureRuntime: dotnet => {
console.log("in configureRuntime");
dotnet.withEnvironmentVariable("MONO_LOG_LEVEL", "debug");
dotnet.withEnvironmentVariable("MONO_LOG_MASK", "all");
}
}
});
</script>
</body>
```
Loading