question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

error when trying to load the @walletconnect/web3-provider lib in an iframe

See original GitHub issue

I’m building a dApp which uses the @walletconnect/web3-provider lib indirectly. Locally and during testing everything works great, the issue comes when I deploy the app as it gets executed in an iframe:

main.js:formatted:134093 Uncaught DOMException: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.

I traced back the exception to the storage utility class of this monorepo.

I believe the problem comes from this part:

export function unsafeGetFromWindow<T>(name: string): T | undefined {
  let res: T | undefined = undefined;
  if (typeof window !== "undefined" && typeof window[name] !== "undefined") {
    res = window[name];
  }
  return res;
}

As that is compiled down to:

"undefined" != typeof window && void 0 !== window.localStorage && (a = window.localStorage),

Which ends up throwing the exception.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
joshstevens19commented, Jul 16, 2020

Safari blocks storing anything in local storage within an iframe. web3 use to use local storage without try catching it and this did not allow you to be able to use web3 in an iframe supporting every browser. A try-catch will solve this but if the lib needs local storage it should probably look into the new storage API which safari now supports - https://developer.mozilla.org/en-US/docs/Web/API/Storage_Access_API to allow this to support iframes in safari (which quite a lot of wallet integrations would be using to add protection between cross-site domains and holding the private key in memory without the integrator being able to get to it).

0reactions
finessevanescommented, Dec 1, 2022

Hey @ramirotw, @wswarren12 are either one of you still experiencing this issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Wallet Connect / Web3 Provider showing a lot of errors just by ...
I want to use "@walletconnect/web3-provider" JS library in my project, ... Here is the part of the error message as it appears in...
Read more >
How to Use Web3React in Your Next Project - Linum Labs
This is used internally in the library when errors happen - web3react will call setError and try to reload. You can also use...
Read more >
framehq/general - Gitter
I'm developing a browser in Electron. Can it create a window which loads Frame's index.html with all its functionalities? @floating.
Read more >
Error - Can't resolve '@walletconnect/web3-provider'
When walletconnect is installed I can't deploy code successfully to cloud. So I removed walletconnect and deployed successfully.
Read more >
Web3Modal Demo - CodePen Embed
"use strict"; /** * Example JavaScript code that interacts with the page and ... the wallet const web3 = new Web3(provider); console.log("Web3 instance...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found