WebAssembly Native Messaging host
Installation and usage on Chrome and Chromium
- Compile
nm_c.cto WASM
$ git clone https://github.com/guest271314/native-messaging-webassembly
$ cd native-messaging-webassembly
$ /path/to/wasi-sdk-19.0/bin/clang nm_c.c -o nm_c.wasm
or compile nm_javy.js to WASM using javy
javy build nm_javy.js -o nm_javy.wasm
Optionally optimize with
wasmtime compile --optimize opt-level=s nm_javy.wasm
and adjust the path in nm_javy_wasm.sh to nm_javy.cwasm
- Download and save
wasmtimeexecutable to the extension directory. - Navigate to
chrome://extensions. - Toggle
Developer mode. - Click
Load unpacked. - Select native-messaging-webassembly folder.
- Note the generated extension ID.
- Open
nm_wasm.jsonin a text editor, set"path"to absolute path ofnm_c_wasm.sh,nm_c_wat.sh, ornm_javy_wasm.shandchrome-extension://<ID>/using ID from 7 in"allowed_origins"array. - Copy the file to Chrome or Chromium configuration folder, e.g., Chromium on *nix
~/.config/chromium/NativeMessagingHosts; Chrome dev channel on *nix~/.config/google-chrome-unstable/NativeMessagingHosts. - Make sure
*.shfiles are executable executable; for WAT embedded innm_c_wat.shwe usekill_wasmtime.shto terminatewasmtimeusing polling ofnm_c_wat.shbecause process substitution keepswasmtimerunning after the Native Messaging host is disconnected and exits. - To test click
service workerlink in panel of unpacked extension which is DevTools forbackground.jsin MV3ServiceWorker, observe echo'ed message from WASI Native Messaging host. To disconnect runport.disconnect().
The Native Messaging host echoes back the message passed.
Do What the Fuck You Want to Public License WTFPLv2