#messaging #native #serde-json #de #serialization #web-extension #documentation

yanked web-ext-native-messaging

WebExtension native messaging with serde_json as the (de)serializer

0.1.0 Sep 4, 2021

#6 in #web-extension

MIT/Apache

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

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
~36K SLoC