#native #messaging #web-extension #documentation #reading

webextension-native-messaging

WebExtension native messaging library for Rust

2 stable releases

1.0.1 Oct 2, 2022

#1 in #web-extension

Download history 16/week @ 2023-12-03 1/week @ 2024-01-14 13/week @ 2024-02-18 37/week @ 2024-02-25 14/week @ 2024-03-03 9/week @ 2024-03-10 6/week @ 2024-03-17

67 downloads per month

MIT/Apache

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.5MB
~34K SLoC