SpiderMonkey JavaScript and WebAssembly engine Shell Native Messaging Host
Installation and usage on Chrome and Chromium
- Navigate to
chrome://extensions
. - Toggle
Developer mode
. - Click
Load unpacked
. - Select native-messaging-spidermoney-shell folder.
- Note the generated extension ID.
- Open
nm_spidermonkey.json
in a text editor, set"path"
to absolute path ofnm_spidermonkey.js
andchrome-extension://<ID>/
using ID from 5 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
; and similar for Chrome For Testing. - Make sure
nm_spidermonkey.js
is executable. To download SpiderMonkey shell
wget --show-progress \
--progress=bar \
--output-document jsshell.zip \
https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central/jsshell-linux-x86_64.zip \
&& unzip jsshell.zip \
&& rm jsshell.zip
or using jsvu
bun install jsvu
./node_modules/.bin/jsvu --os=linux64 --engines=spidermonkey
and use the appropriate path to the js
or spidermonkey
executable, respectively in nm_spidermoney.js
, e.g.,
#!/usr/bin/env -S /home/user/bin/js
or
#!/usr/bin/env -S /home/user/.jsvu/engines/spidermonkey/spidermonkey
- To test click
service worker
link in panel of unpacked extension which is DevTools for background.js in MV3ServiceWorker
, observe echo'ed message from SpiderMonkey Native Messaging host. See Notes.
SpiderMonkey JavaScript/WebAssembly engine Shell does not expect to be used as a Native Messaging host. Standard input and standard output are not specified by ECMA-262. We have to work around that fact in this js
shell.
JavaScript runtimes tested so far, include QuickJS, txiki.js, Deno, Node.js, Bun. Each process standard input and output differently. With the aforementioned runtimes we can maintain a persistent connection between client and host using connectNative()
. See NativeMessagingHosts.
While we use connectNative
here instead of sendNativeMessage
that is only to send a trailing "\r\n\r\n"
for readline()
to stop reading (blocking), echo the message back then call disconnect()
, repeat for each message, to avoid the js
shell hanging on subsequent messages from client to host.
For the above reasons native-messaging-spidermonkey-shell
will not be added to the working Native Messaging hosts repository listed above until we get this working as intended.
For differences between OS and browser implementations see Chrome incompatibilities.
Do What the Fuck You Want to Public License WTFPLv2