From cb334aab0d5e9850047e156823ab6b8ab90c8fc9 Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Mon, 3 Jun 2024 00:16:40 +0200 Subject: [PATCH] Do a bad code, because chrome doesn't work when you try to write good code --- src/ext/lib/comms/CommsClient.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/ext/lib/comms/CommsClient.ts b/src/ext/lib/comms/CommsClient.ts index 29f10a0..42a8cfc 100644 --- a/src/ext/lib/comms/CommsClient.ts +++ b/src/ext/lib/comms/CommsClient.ts @@ -134,9 +134,17 @@ class CommsClient { // content script client and popup client differ in this one thing if (this.origin === CommsOrigin.Popup) { - return this.port.postMessage(message, context); + try { + return this.port.postMessage(message); + } catch (e) { + console.log('chrome is shit, lets try to bruteforce ...', e); + const port = chrome.runtime.connect(null, {name: this.name}); + port.onMessage.addListener(this._listener); + return port.postMessage(message); + } } - return browser.runtime.sendMessage(null, message, null); + // send to server + return chrome.runtime.sendMessage(null, message, null); } /**