guest271314 / native-messaging-d8

d8 Native Messaging host

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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://<ID>/ 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 for why Bash is used to read standard input stream to d8. To download V8 using jsvu or 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
  1. 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 ("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.

Compatibility

For differences between OS and browser implementations see Chrome incompatibilities.

License

Do What the Fuck You Want to Public License WTFPLv2

About

d8 Native Messaging host

License:Do What The F*ck You Want To Public License


Languages

Language:JavaScript 100.0%