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