From 1683c652f64c58771d2253b85372284d095d5669 Mon Sep 17 00:00:00 2001 From: Philipp Giese <187786+frontendphil@users.noreply.github.com> Date: Wed, 18 Dec 2024 11:13:00 +0100 Subject: [PATCH] fix: move ensureIframe method out of global scope (#388) --- extension/src/connect/contentScripts/dApp.ts | 40 +++++++++++--------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/extension/src/connect/contentScripts/dApp.ts b/extension/src/connect/contentScripts/dApp.ts index d40d7911..7e4698fd 100644 --- a/extension/src/connect/contentScripts/dApp.ts +++ b/extension/src/connect/contentScripts/dApp.ts @@ -4,25 +4,31 @@ import { } from '@/messages' import { invariant } from '@epic-web/invariant' -function ensureIframe() { - let node: HTMLIFrameElement | null = document.querySelector( - 'iframe[src="https://connect.pilot.gnosisguild.org/"]', - ) - - if (!node) { - node = document.createElement('iframe') - node.src = 'https://connect.pilot.gnosisguild.org/' - node.style.display = 'none' - - const parent = document.body || document.documentElement - parent.append(node) - } - - return node -} - // wait for connection from ConnectProvider (running in extension page), then inject iframe to establish a bridge to the user's injected wallet chrome.runtime.onConnect.addListener((port) => { + // DO NOT MOVE THIS OUT OF THIS SCOPE! + // Apparently when building for production this + // method might receive a name that clashes with + // another variable on the global scope. This results + // in the extension not being able to create a port + // to a DApp and, therefore, not working. Crazy, right? + const ensureIframe = () => { + let node: HTMLIFrameElement | null = document.querySelector( + 'iframe[src="https://connect.pilot.gnosisguild.org/"]', + ) + + if (!node) { + node = document.createElement('iframe') + node.src = 'https://connect.pilot.gnosisguild.org/' + node.style.display = 'none' + + const parent = document.body || document.documentElement + parent.append(node) + } + + return node + } + const iframe = ensureIframe() // relay requests from the panel to the connect iframe