Tested with .Net version 8.0.402, Jint v4.0.3.
Note
Note that printing to console currently is made from C# code. Returning the result to JS by using result.UnwrapIfPromise()
looks like still impossible, probably due to Error: Cannot wait on monitors on this runtime.
.
-
Open this repo in devcontainer, e.g. using Github Codespaces. Type or copy/paste following commands to devcontainer's terminal.
-
Install .Net workloads to handle WASM:
dotnet workload install wasm-tools
dotnet workload install wasm-experimental
cd
into the folder of this example:
cd browser-and-node-Jint/browser
- Create new .Net project using
wasmbrowser
template:
dotnet new wasmbrowser
- Install Jint package as dependency:
dotnet add package Jint --version 4.0.3
- Replace generated HelloWorld-like
Program.cs
andwwwroot
contents with HTTP-enabled ones:
cp ../Program.cs ./
cp ../index.html ./wwwroot/
cp ../main.js ./wwwroot/
- Compile the example:
dotnet build
- Generate bunch of self-signed development SSL certificates:
dotnet dev-certs https
- Run debug HTTP server to temporarily publish project to Web:
dotnet run
Codespace will show you "Open in Browser" button. Just click that button or obtain web address from "Forwarded Ports" tab.
-
As
index.html
and about 23MB of js and wasm files are loaded into browser, refer to browser developer console to see the results. -
If you want to publish this on your own server, you can run bundling by:
dotnet publish -c Release
Perform your own experiments if desired.