Browser Host
MyGame.web is a browser-wasm host plus the HTML that embeds your game. Its published MyGame.web/AppBundle/ directory is a static site.
dotnet publish MyGame.webThis page covers host anatomy
Web / Browser (WASM) is the guide to publishing, serving, development, and browser limits.
Program
using Godot;
using Engine = twodog.Engine;
internal static class Program
{
private static int Main(string[] args)
{
Engine.RegisterWebPluginsInitializer(TwoDogWebBoot.PluginsInitializer());
var engine = new Engine("MyGame", null, args);
engine.Start();
GD.Print("2dog is running in the browser!");
engine.Run();
return 0;
}
}This differs from the generic host in three ways:
- Register
TwoDogWebBoot.PluginsInitializer()beforeStart(). The browser cannot loadGodotPlugins.dllfrom disk, so the game assembly exposes its source-generated initializer directly.TwoDogWebBoot.cslives in this host folder but compiles into the game assembly through a guardedCompile Includein the game csproj - scripts are resolved from the assembly holding the initializer. - Pass
nullas the project path. At runtime, the page mounts the exportedgodot.pckthrough--main-pack;GodotProjectDiris still needed to export that pack at build time. - Do not dispose the engine or call
Iteration().Run()hands the loop to Emscripten and returns immediately. UseRun(perFrame)for host-side frame work.
Skipping initializer registration fails during Start(). Calling the browser registration API on desktop throws PlatformNotSupportedException.
Project Differences
The shared host project is documented in Hosts. The browser host adds:
<PropertyGroup>
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
<GodotProjectDir>..</GodotProjectDir>
<TwoDogRemoveDuplicateGodotAnalyzers>true</TwoDogRemoveDuplicateGodotAnalyzers>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="2dog.engine" Version="4.7.1.65"/>
<PackageReference Include="2dog.browser-wasm" Version="[4.7.1.35]"/>
<ProjectReference Include="../MyGame.csproj"/>
</ItemGroup>
<ItemGroup>
<TrimmerRootAssembly Include="MyGame"/>
<TrimmerRootAssembly Include="$(TargetName)"/>
</ItemGroup>2dog.browser-wasm links libgodot.a, exports the .pck, and assembles AppBundle/. The game and host assemblies are rooted because Godot resolves scripts through reflection and publishing trims unused code.
The host also contains:
.gdignore, which keeps Godot out of the host folder;Directory.Build.props, which defaults browser builds toRelease;global.json, which pins a .NET 10 SDK;wwwroot/, which contains the page shell and static files;TwoDogWebBoot.cs, the web bootstrap compiled by the game project (see Program); this host excludes it from its own compile globs.
Host Properties
| Property | Default | Purpose |
|---|---|---|
TwoDogWebVariant | release | Use debug with an explicit 2dog.browser-wasm.debug reference |
TwoDogExportPack | true | Export the project during publish; false uses your wwwroot/godot.pck |
TwoDogWebExportPreset | Web | Export preset in export_presets.cfg |
TwoDogWebPackName | godot.pck | Deployed pack name |
TwoDogWebSizeManifest | true | Write twodog.sizes.json for the shell's progress bar |
TwoDogWebStripMaps | true for release | Delete *.js.map sourcemaps from the bundle |
TwoDogWebPrecompress | true | Write .br/.gz siblings next to payload files |
Loading-performance knobs (WasmInitialHeapSize, WasmEmitSymbolMap, compression and serving guidance) are covered in Web / Browser (WASM).
Publishing requires a .NET 10 SDK with the wasm workload:
dotnet workload install wasm-toolsContinue with Web / Browser (WASM) for the publishing workflow.