tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

messaging.js (758B)


      1 // This message should not be handled
      2 browser.runtime.sendNativeMessage("badNativeApi", "errorerrorerror");
      3 
      4 async function runTest() {
      5  const response = await browser.runtime.sendNativeMessage(
      6    "browser",
      7    "testContentBrowserMessage"
      8  );
      9 
     10  browser.runtime.sendNativeMessage("browser", `response: ${response}`);
     11 
     12  const port = browser.runtime.connectNative("browser");
     13  port.onMessage.addListener(response => {
     14    if (response.action === "disconnect") {
     15      port.disconnect();
     16      return;
     17    }
     18 
     19    port.postMessage(`response: ${response.message}`);
     20  });
     21 
     22  port.onDisconnect.addListener(() =>
     23    browser.runtime.sendNativeMessage("browser", { type: "portDisconnected" })
     24  );
     25 
     26  port.postMessage("testContentPortMessage");
     27 }
     28 
     29 runTest();