0.1.0 |
|
---|
#5 in #web-extension
8KB
78 lines
web-ext-native-messaging
WebExtension native messaging with serde_json as the (de)serializer.
Documentation
See docs.rs for documentation.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
lib.rs
:
web-ext-native-messaging
WebExtension native messaging with serde_json
as the (de)serializer.
Reading
In your web extension:
const port = browser.runtime.connectNative('native executable');
port.postMessage('Hey, there!');
Then in your native executable:
use web_ext_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 web_ext_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
~37K SLoC