]> git.r.bdr.sh - rbdr/junction/blobdiff - extension/content_script.js
Inject script only once
[rbdr/junction] / extension / content_script.js
index c344bd945ca94e23ef5f954460f201cc98b6a61f..9d4666931b9fae6702c31a0dedda56e55d51ecff 100644 (file)
@@ -26,6 +26,11 @@ const internals = {
     console.error(error.stack || error);
   },
 
+  connect() {
+    internals.port = chrome.runtime.connect({ name: "content" });
+    internals.port.onMessage.addListener(internals.onMessage);
+  },
+
   async joinAudioCall({ currentUrl, tada }) {
     try {
       const mediaStream = await startMedia();
@@ -84,8 +89,10 @@ const internals = {
   },
 };
 
-internals.port = chrome.runtime.connect({ name: "content" });
-internals.port.onMessage.addListener(internals.onMessage);
+internals.connect();
+chrome.runtime.onConnect.addListener(() => {
+  internals.connect();
+});
 
 console.debug("Content Script Loaded");