2 stable releases
1.0.1 | Oct 2, 2022 |
---|
#2 in #web-extension
8KB
75 lines
WebExtension 🛰 Native Messaging
WebExtension native messaging library for Rust.
Usage
For documentation and examples see docs.rs.
License
Distributed under the Apache License 2.0 and MIT licenses, see LICENSE-Apache and LICENSE-MIT for more information.
lib.rs
:
WebExtension Native Messaging
WebExtension native messaging library for Rust.
Reading
In your web extension:
const port = browser.runtime.connectNative('native executable');
port.postMessage('Hey, there!');
Then in your native executable:
use webextension_native_messaging::read_message;
let message = read_message::<String>().unwrap();
println!("{}", message);
Writing
In your web extension:
const port = browser.runtime.connectNative('native executable');
port.onMessage.addListener((message) => {
console.log(message);
});
Then in your native executable:
use webextension_native_messaging::write_message;
let message = "Hey, there!".to_string();
write_message(&message).unwrap();
See the native messaging documentation for precise instructions on how to send and receive messages.
Dependencies
~0.8–1.7MB
~36K SLoC