diff --git a/src/ext/UWServer.ts b/src/ext/UWServer.ts index a91c6c4..34dc732 100644 --- a/src/ext/UWServer.ts +++ b/src/ext/UWServer.ts @@ -312,6 +312,7 @@ export default class UWServer { if (!activeTab || activeTab.length < 1) { this.logger.log('warn', 'comms', 'There is no active tab for some reason. activeTab:', activeTab); + return null; } const url = activeTab[0].url; diff --git a/src/ext/lib/EventBus.ts b/src/ext/lib/EventBus.ts index 40c5810..efee880 100644 --- a/src/ext/lib/EventBus.ts +++ b/src/ext/lib/EventBus.ts @@ -26,6 +26,14 @@ export default class EventBus { private upstreamBus?: EventBus; private comms?: CommsClient | CommsServer; + private disableTunnel: boolean = false; + private popupContext: any = {}; + + setupPopupTunnelWorkaround(context: EventBusContext): void { + this.disableTunnel = true; + this.popupContext = context; + } + //#region lifecycle destroy() { this.commands = null; @@ -107,13 +115,22 @@ export default class EventBus { * @param config */ sendToTunnel(command: string, config: any) { - window.parent.postMessage( - { - action: 'uw-bus-tunnel', - payload: {action: command, config} - }, - '*' - ); + if (!this.disableTunnel) { + window.parent.postMessage( + { + action: 'uw-bus-tunnel', + payload: {action: command, config} + }, + '*' + ); + } else { + // because iframe UI components get reused in the popup, we + // also need to set up a detour because the tunnel is closed + // in the popup + if (this.comms) { + this.comms.sendMessage({command, config, context: this.popupContext}, this.popupContext); + } + } } diff --git a/src/ext/lib/comms/CommsServer.ts b/src/ext/lib/comms/CommsServer.ts index 7adaed4..1ad43af 100644 --- a/src/ext/lib/comms/CommsServer.ts +++ b/src/ext/lib/comms/CommsServer.ts @@ -134,7 +134,7 @@ class CommsServer { return; } for (const framePort in this.ports[tab][frame]) { - this.ports[tab][frame][framePort].postMessage(message); + this.ports[tab][frame][framePort].postMessage(JSON.parse(JSON.stringify(message))); } } @@ -156,6 +156,7 @@ class CommsServer { this.logger.log('info', 'comms', `%c[CommsServer::sendToFrame] attempting to send message to tab ${tab}, frame ${frame}`, "background: #dda; color: #11D", message); try { + this.sendToFrameContentScripts(message, tab, frame, port); } catch (e) { this.logger.log('error', 'comms', `%c[CommsServer::sendToFrame] Sending message failed. Reason:`, "background: #dda; color: #11D", e); diff --git a/src/popup/App.vue b/src/popup/App.vue index 10e06da..0139784 100644 --- a/src/popup/App.vue +++ b/src/popup/App.vue @@ -32,7 +32,7 @@ :settings="settings" :eventBus="eventBus" :site="site" - :frame="site.frame[0]" + :frame="selectedFrame" >
@@ -48,10 +48,11 @@