Skip to content

Commit

Permalink
fix: move ensureIframe method out of global scope (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
frontendphil authored Dec 18, 2024
1 parent 08e2932 commit 1683c65
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions extension/src/connect/contentScripts/dApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1683c65

Please sign in to comment.