fix: 重复监听

This commit is contained in:
song_xiao_lin
2024-05-15 14:43:04 +08:00
committed by go0p
parent e150379c7f
commit a4840c9c5e
5 changed files with 195 additions and 144 deletions
+10 -9
View File
@@ -83,13 +83,14 @@ const pageFunction = (code) => {
chrome.runtime.onConnect.addListener(function (port) {
console.assert(port.name === "content-to-ex");
port.onMessage.addListener(function (msg) {
console.log("[content-to-ex]", msg)
});
port.onDisconnect.addListener(function () {
console.error("[content-to-ex] Disconnected from port.");
});
// port.postMessage({action: "TEST POST MESSAGE"});
if (!port.hasListener) {
port.onMessage.addListener(function (msg) {
console.log("[content-to-ex]", msg)
});
port.onDisconnect.addListener(function () {
console.error("[content-to-ex] Disconnected from port.");
});
// port.postMessage({action: "TEST POST MESSAGE"});
port.hasListener = true;
}
});