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

createSolanaRpcSubscriptions in a browser extension throws error #3652

Open
liepauls opened this issue Nov 29, 2024 · 2 comments · May be fixed by #3658
Open

createSolanaRpcSubscriptions in a browser extension throws error #3652

liepauls opened this issue Nov 29, 2024 · 2 comments · May be fixed by #3658
Assignees
Labels
bug Something isn't working

Comments

@liepauls
Copy link

Overview

createSolanaRpcSubscriptions in a browser extension throws error Cannot read properties of undefined (reading 'addEventListener')

Steps to reproduce

  1. Create a browser extension
  2. Run something along the lines of:
const rpc = createSolanaRpc('https://api.devnet.solana.com')
const rpcSubscriptions = createSolanaRpcSubscriptions('wss://api.devnet.solana.com')

const sendAndConfirmTransaction = sendAndConfirmTransactionFactory({
  rpc,
  rpcSubscriptions,
})

const signedTx = ...

sendAndConfirmTransaction(signedTx, { commitment: 'confirmed' })

Please, let me know if a more detailed info on how to reproduce the error is needed 🤞

Description of bug

When sendAndConfirmTransaction is called, Cannot read properties of undefined (reading 'addEventListener') is thrown.

The error probably comes from here.

@liepauls liepauls added the bug Something isn't working label Nov 29, 2024
@steveluscher
Copy link
Collaborator

Nice find. Which browser is this?

I presume that in contentScripts that globalThis.window is undefined but globalThis is an EventTarget. It looks like in browser-ish environments, globalThis is always an EventTarget, so it should be safe to change this to globalThis.addEventListener everywhere.

@liepauls
Copy link
Author

liepauls commented Dec 2, 2024

Hi @steveluscher, thanks for addressing the issue 🙇

Occured in Brave, tried your fix and it looks like the problem is gone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants