https://github.com/guest271314/native-messaging-spidermonkey-shell
SpiderMonkey Shell Native Messaging host
https://github.com/guest271314/native-messaging-spidermonkey-shell
javascript js native-messaging native-messaging-host shell spidermonkey
Last synced: 6 months ago
JSON representation
SpiderMonkey Shell Native Messaging host
- Host: GitHub
- URL: https://github.com/guest271314/native-messaging-spidermonkey-shell
- Owner: guest271314
- License: wtfpl
- Created: 2024-06-18T01:50:35.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-06-30T00:59:07.000Z (11 months ago)
- Last Synced: 2024-06-30T13:41:19.486Z (11 months ago)
- Topics: javascript, js, native-messaging, native-messaging-host, shell, spidermonkey
- Language: JavaScript
- Homepage:
- Size: 39.1 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
SpiderMonkey JavaScript and WebAssembly engine Shell Native Messaging Host
Installation and usage on Chrome and Chromium
1. Navigate to `chrome://extensions`.
2. Toggle `Developer mode`.
3. Click `Load unpacked`.
4. Select native-messaging-spidermoney-shell folder.
5. Note the generated extension ID.
6. Open `nm_spidermonkey.json` in a text editor, set `"path"` to absolute path of `nm_spidermonkey.js` and `chrome-extension:///` using ID from 5 in `"allowed_origins"` array.
7. 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.
8. 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`](https://github.com/GoogleChromeLabs/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
```
9. To test click `service worker` link in panel of unpacked extension which is DevTools for background.js in MV3 `ServiceWorker`, observe echo'ed message from SpiderMonkey Native Messaging host. See [Notes](https://github.com/guest271314/native-messaging-spidermonkey-shell/blob/main/README.md#notes).### Notes
[SpiderMonkey JavaScript/WebAssembly engine](https://spidermonkey.dev/) 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()`](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/connectNative). See [NativeMessagingHosts](https://github.com/guest271314/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](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Chrome_incompatibilities#native_messaging).
# License
Do What the Fuck You Want to Public License [WTFPLv2](http://www.wtfpl.net/about/)