Skip to content

projektorius96/native_messaging_host

Repository files navigation

Project name: native_messaging_host (2025 Q3 edition)

NOTE: The codebase is Windows-users oriented!

Prerequisites

  • In order to set up the native messaging host (hereinafter - "NMH") on your local machine referring to specification that describes how to implement it;
  • Load the extension on Chromium-based browser of choice (e.g. Chrome), the proof-of-case extension can be found under ./nmh-extension--unpacked/ path (directory).

Build your executable

Before running the command, it assumes your current working directory is native_messaging_host on your active terminal (I use Git Bash for Windows, you may use complete WSL 2.0 or later), then simply run
dart compile exe ./bin/main.dart -o ./bin/main.exe; NOTE: you do not need to run it from the terminal, the extension itself will !

Testing NMH

  1. Load the unpacked extension, and click on your extension icon pinned to your browser's toolbar
  2. Open the extension service worker console and expect the following output as shown in Figure 1: Figure 1
  3. Build something incredible with Dart and JavaScript (Chrome Extensions), respecting the stdio limitations as described in the specification.

Implementation remarks

I am not gonna lie, I got stuck at least once, credits to GitHub Copilot for the guidance ❤️

Minimal robust algorithm (steps):

  1. Maintain a buffer of unconsumed bytes.
  2. Append each incoming chunk to that buffer.
  3. While buffer length >= 4:
  • Read length = getInt32(buffer[0..3], Endian.little).
  • If buffer length >= 4 + length:
    • Extract payload = buffer[4 .. 4+length-1].
    • Process payload (utf8.decode -> jsonDecode).
    • Remove consumed bytes (0 .. 4+length-1) from buffer.
    • Continue loop (there may be another full frame).
  • Else:
    • Break and wait for more bytes to arrive (partial payload).
  1. Repeat on next chunk.

Milestones

  1. Write a test that temporarily would generate ./add_this_registry.reg populating the '@=' with concrete value of the path, rather than something like DISKVOLUME:\\PATH_TO_DART_PACKAGE_BIN_DIR\\manifest.json as given in the initial project template; optionally, leverage package:puppeteer package dependency by extracting currently tested NMH's "ID" value that would in turn replace ./bin/manifest.json file's YOUR_EXTENSION_GENERATED_ID placeholder as given in the initial project template - this two-step testing process would reduce the significant amount of manual intervention by consumer or tester oneself, however for this proof-of-case scenario, it does a job as is...

Made with ♥ by projektorius96 a.k.a. Lukas Gaučas

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published