Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const context = {
- port: null,
- }
- const messages = [
- "ping",
- "pong",
- "foobar",
- "Ф",
- ];
- let index = 0;
- function initNativePort() {
- const port = context.port = browser.runtime.connectNative('webextdev');
- port.onMessage.addListener((aResponse) => {
- console.log('Native message', aResponse);
- });
- }
- browser.browserAction.onClicked.addListener(() => {
- if (!context.port) {
- initNativePort();
- }
- console.log('Sending native message');
- const cMessage = messages[index % messages.length];
- ++index;
- context.port.postMessage(cMessage);
- });
Advertisement
Add Comment
Please, Sign In to add comment