- Python
- C
- C++
- QuickJS
- txiki.js
- Node.js
- Deno
- Bun
- WebAssembly/WASI
- Bash
- SpiderMonkey
jsshell - V8
d8shell - TypeScript
- Amazon Web Services - Labs LLRT (Low Latency Runtime)
- Rust
teecommand (Busybox; GNU Coreutils)- Static Hermes
- AssemblyScript
Tested echoing new Array(209715) (1 MB in JSON format) from client to host.
- Chrome Developers
- MDN Web Docs
- Microsoft Edge Developer documentation
- Messaging between the app and JavaScript in a Safari web extension
Native messaging protocol (Chrome Developers)
Chrome starts each native messaging host in a separate process and communicates with it using standard input (
stdin) and standard output (stdout). The same format is used to send messages in both directions; each message is serialized using JSON, UTF-8 encoded and is preceded with 32-bit message length in native byte order. The maximum size of a single message from the native messaging host is 1 MB, mainly to protect Chrome from misbehaving native applications. The maximum size of the message sent to the native messaging host is 4 GB.
Installation and usage on Chrome and Chromium
- Navigate to
chrome://extensions. - Toggle
Developer mode. - Click
Load unpacked. - Select
native-messaging-<host>folder, e.g.,native-messaging-webassembly. - Note the generated extension ID.
- Open, for example,
nm_c_wasm.jsonin a text editor, set"path"to absolute path ofnm_c.wasmandchrome-extension://<ID>/using ID from 5 in"allowed_origins"array. - Copy the
nm_c_wasm.jsonfile 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
wasmtimefor WASM host, or the single host file, e.g. when using QuickJSnm_qjs.js,are executable. - To test click
service workerlink in panel of unpacked extension which is DevTools forbackground.jsin MV3ServiceWorker, observe echo'ed message from Native Messaging host to client in DevToolsconsole. To disconnect runport.disconnect().
For differences between OS and browser implementations see Chrome incompatibilities. For Firefox or Nightly usage see also Can't get response in Ubuntu #506.
nm_standalone_test.js tests the Native Messaging hosts outside of the browser. Example usage
deno -A nm_standalone_test.js ./nm_nodejs.js native-messaging-extension://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/
- Capture system and specific audio output, stream output to browser. capture_system_audio
- Send text or SSML to local eSpeak NG speech synthesis engine, stream output to browser native-messaging-espeak-ng
- Turn local PHP server on and off from browser native-messaging-php, see also
deno-serverbranch innative-messaging-espeak-ng - WAT embedded in a Bash shell script nm_c_wat.sh (see usage note at 10.)
- Full duplex streaming from and to the browser over HTTP/2 with WHATWG
fetch()and Streams (Deno version, Node.js version) nm_host.jsandnm_typescript.ts(derived fromnm_host.js) are intended to be JavaScript runtime agnostic, can be run bynode,deno, andbunnm_bash_standalone.shdoes not use subshells- rhasspy/piper local TTS stream native-messaging-piper
- JavaScript in WASM using Bytecode Alliance's Javy nm_javy.js, see native-messaging-webassembly/README.md
- Write files to local file system from Web pages native-messaging-file-writer
Do What the Fuck You Want to Public License WTFPLv2