Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: move ensureIframe method out of global scope #388

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading