d8 Native Messaging Host
Installation and usage on Chrome and Chromium
- Navigate to
chrome://extensions
. - Toggle
Developer mode
. - Click
Load unpacked
. - Select
native-messaging-d8
folder. - Note the generated extension ID.
- Open
nm_d8.json
in a text editor, set"path"
to absolute path ofnm_d8.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_d8.js
is executable. See Notes for why Bash is used to read standard input stream tod8
. To download V8 usingjsvu
oresvu
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
- To test click
service worker
link in panel of unpacked extension which is DevTools for background.js in MV3ServiceWorker
, observe echo'ed message fromd8
Native Messaging host. The communication mechanism can be extended to run V8 viad8
from any arbitrary Web page using various means, including, but not limited to utilizing"externally_connectable"
to message to and from theServiceWorker
on specific Web pages over IPC;"web_accessible_resources"
to append an extensioniframe
to any document and usepostMessage()
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.
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")
We work around this in the d8
shell by using os.system()
with pgrep
command to get the PID of the current process, then or GNU Coreutils head
,
dd
command, or QuickJS to read /proc/$@/fd/0
, then echo the STDIN to the current d8
process to d8
.
For differences between OS and browser implementations see Chrome incompatibilities.
Do What the Fuck You Want to Public License WTFPLv2