WebAssembly Native Messaging host
Installation and usage on Chrome and Chromium
- Compile
nm_c.c
to 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 compile 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
wasmtime
executable 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.json
in a text editor, set"path"
to absolute path ofnm_c_wasm.sh
,nm_c_wat.sh
, ornm_javy_wasm.sh
andchrome-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
*.sh
files are executable executable; for WAT embedded innm_c_wat.sh
we usekill_wasmtime.sh
to terminatewasmtime
using polling ofnm_c_wat.sh
because process substitution keepswasmtime
running after the Native Messaging host is disconnected and exits. - To test click
service worker
link in panel of unpacked extension which is DevTools forbackground.js
in 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