NOTE: The codebase is Windows-users oriented!
- 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).
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 !
- Load the unpacked extension, and click on your extension icon pinned to your browser's toolbar
- Open the extension service worker console and expect the following output as shown in Figure 1:
- Build something incredible with Dart and JavaScript (Chrome Extensions), respecting the stdio limitations as described in the specification.
I am not gonna lie, I got stuck at least once, credits to GitHub Copilot for the guidance ❤️
Minimal robust algorithm (steps):
- Maintain a buffer of unconsumed bytes.
- Append each incoming chunk to that buffer.
- 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).
- Repeat on next chunk.
- Write a test that temporarily would generate
./add_this_registry.reg
populating the '@=' with concrete value of the path, rather than something likeDISKVOLUME:\\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'sYOUR_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