Native Messaging Helper for WebExtensions
This Rust crate provides a simple way to create, register, and manage native messaging host applications for WebExtensions. It includes cross-platform support for Chrome and Firefox, with functionalities to install, verify, and remove native messaging manifests, and enables asynchronous communication with WebExtensions.
Features
- Cross-platform Support: Manage native messaging manifests for Chrome and Firefox on Linux and macOS.
- Automatic Manifest Installation: Easily create and install native messaging manifests for supported browsers.
- Manifest Verification and Removal: Check if a manifest is installed and remove it if necessary.
- Asynchronous Message Handling: Use event loops and asynchronous functions to encode, send, and receive messages.
Table of Contents
Getting Started
Prerequisites
- Rust
- Cargo package manager
Installation
Add this crate to your Cargo.toml:
[]
= "0.1.0"
Usage
Creating and Installing a Manifest
To create and install a native messaging manifest, use the install::install function from the native_messaging crate with the manifest's name, description, path to the native app, and the target browsers:
use install;
This will create and install a manifest for the specified browsers if the path exists.
Sending and Receiving Messages
To enable message communication with your WebExtension, use the host module functions to handle messaging operations such as get_message to read messages, send_message to send responses, and event_loop to manage asynchronous message handling.
Example: Reading a Message
use get_message;
use tokio;
async
Example: Sending a Message
use send_message;
use Serialize;
use tokio;
async
Example: Running an Event Loop
To continuously receive messages and handle them, you can set up an event_loop using an async callback:
use ;
use tokio;
async
async
Verifying and Removing a Manifest
Verifying Manifest Installation
You can check if a manifest is installed using verify from the install module:
use verify;
Removing a Manifest
To remove a previously installed manifest, use remove from the install module:
use remove;
Contributing
Contributions are welcome! Please follow these steps:
- Fork this repository.
- Create a new branch (
feature/my-feature). - Commit your changes (
git commit -m 'Add feature'). - Push to the branch (
git push origin feature/my-feature). - Create a new Pull Request.
Feel free to report bugs or suggest features by opening an issue.
Code of Conduct
Please follow the Contributor Covenant Code of Conduct in all your interactions with this project.
License
This project is licensed under the MIT License. See the LICENSE file for details.
This library makes managing native messaging easier, letting you focus on building your WebExtension instead of handling low-level manifest and messaging details. Happy coding!