An open API service indexing awesome lists of open source software.

https://github.com/guest271314/native-messaging-d8

d8 Native Messaging host
https://github.com/guest271314/native-messaging-d8

d8 javascript native-messaging native-messaging-host shell v8

Last synced: about 2 months ago
JSON representation

d8 Native Messaging host

Awesome Lists containing this project

README

        

d8 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-d8` folder.
5. Note the generated extension ID.
6. Open `nm_d8.json` in a text editor, set `"path"` to absolute path of `nm_d8.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_d8.js` is executable. See [Notes](https://github.com/guest271314/native-messaging-d8#notes) for why Bash is used to read standard input stream to `d8`. To download V8 using [`jsvu`](https://github.com/GoogleChromeLabs/jsvu) or [`esvu`](https://github.com/devsnek/esvu)

```
bun install jsvu
./node_modules/.bin/jsvu --os=linux64 --engines=v8
```
```
bun install esvu
./node_modules/.bin/esvu install v8
```
and use the appropriate path to the `v8` executable

```
#!/usr/bin/env -S /home/user/.jsvu/engines/v8/v8
```
```
#!/usr/bin/env -S /home/user/.esvu/engines/v8/d8
```

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 `d8` Native Messaging host. The communication mechanism can be extended to run V8 via `d8` from any arbitrary Web page using various means, including, but not limited to utilizing `"externally_connectable"` to message to and from the `ServiceWorker` on specific Web pages over IPC; `"web_accessible_resources"` to append an extension `iframe` to any document and use `postMessage()` to transfer messages between browsing contexts; an offscreen document or side-panel document to connect to the host and transfer messages back and forth to the arbitrary Web page in the browser, et al.

### Notes

[d8](https://v8.dev/docs/d8) ("V8’s own developer shell") does not expect to be used as a Native Messaging host.

Standard input and standard output are not specified by ECMA-262.

V8 maintainers do not currently appear to be interested in extending `d8` capabilities, or the idea of standardizing reading STDIN for JavaScript. See [Implement reading STDIN to an ArrayBuffer. Precedent: `writeFile("/proc/self/fd/1")`](https://groups.google.com/g/v8-users/c/NsnStT6bx3Y/m/Yr_Z1FwgAQAJ)

We work around this in the `d8` shell by using [`os.system()`](https://source.chromium.org/chromium/chromium/src/+/main:v8/src/d8/d8.h;l=647) with [`pgrep`](https://man7.org/linux/man-pages/man1/pgrep.1.html) command to get the PID of the current process, then or GNU Coreutils [`head`](https://www.gnu.org/software/coreutils/manual/html_node/head-invocation.html),
[`dd`](https://www.gnu.org/software/coreutils/manual/html_node/dd-invocation.html#dd-invocation) command, or [QuickJS](https://bellard.org/quickjs/quickjs.html) to read `/proc/$@/fd/0`, then echo the STDIN to the current `d8` process to `d8`.

### Compatibility

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/)