Skip to content

Latest commit

 

History

History
86 lines (56 loc) · 1.93 KB

File metadata and controls

86 lines (56 loc) · 1.93 KB

Use Jint JS interpreter to send HTTP(s) requests from inside WASM in browser

Instructions for this devcontainer

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..

Preparation

  1. Open this repo in devcontainer, e.g. using Github Codespaces. Type or copy/paste following commands to devcontainer's terminal.

  2. Install .Net workloads to handle WASM:

dotnet workload install wasm-tools
dotnet workload install wasm-experimental

Building

  1. cd into the folder of this example:
cd browser-and-node-Jint/browser
  1. Create new .Net project using wasmbrowser template:
dotnet new wasmbrowser
  1. Install Jint package as dependency:
dotnet add package Jint --version 4.0.3
  1. Replace generated HelloWorld-like Program.cs and wwwroot contents with HTTP-enabled ones:
cp ../Program.cs ./
cp ../index.html ./wwwroot/
cp ../main.js ./wwwroot/
  1. Compile the example:
dotnet build

Test with browser

  1. Generate bunch of self-signed development SSL certificates:
dotnet dev-certs https
  1. 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.

  1. As index.html and about 23MB of js and wasm files are loaded into browser, refer to browser developer console to see the results.

  2. If you want to publish this on your own server, you can run bundling by:

dotnet publish -c Release

Finish

Perform your own experiments if desired.