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