Closed arnoudcommandeur closed 3 years ago
this still doesnt work! opens metamask fine on pc wont do anything but load on mobile (chrome)
Any ideas??
`import Web3 from "web3";
const initWeb3 = () => { return new Promise(async (resolve, reject) => { if (window.ethereum) { const web3 = new Web3(window.ethereum); try { await window.ethereum.enable(); resolve(web3); } catch (error) { reject(error); } } else if (window.web3) { const web3 = window.web3; console.log("Injected web3 detected."); resolve(web3); } else { const provider = new Web3.providers.HttpProvider("http://localhost:9545"); const web3 = new Web3(provider); console.log("No web3 instance injected, using Local web3."); resolve(web3); } }); };
export { initWeb3 };`
which app version are you on @CryoWebToken
I could not access window.ethereum on Android until I added the .html ext to the filename. Hope this helps someone.
@jamesmorgan Thanks you don't know how much time I spent trying to figure this out.
What made it worse for me was that this worked perfectly on another app using nuxt but after reading your comment I noticed the
tag in my other app didn't have a whitespace even though the app.html template is exactly the same, same nuxt versions as well.this issue is still there has any one found a fix for this
I think the problem is that metamask tries to inject before html head section load. When I removed the heavy link tags from head tag, the problem was gone.
I was finally able to fix the issue in my app (after an entire day debugging) by removing the following link tags of Google Fonts from the <head>
section:
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
I was finally able to fix the issue in my app (after an entire day debugging) by removing the following link tags of Google Fonts from the
<head>
section:<link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
Why is it working by remove these?
I am still having this issue
Hi there, has anyone solved this issue? Ethereum still fails to inject on android more often than it getting injected. Can someone please help @rekmarks
Describe the bug When I open my DApp, the web3 provider is not always injected. It doesn't make sence I use @metamask/detect-provider or plain window.ethereum call.
To Reproduce Steps to reproduce the behavior
I also tried adding an eventlistener, but this doesn't' work as well:
In my HTML file I added:
<script src="https://unpkg.com/@metamask/detect-provider/dist/detect-provider.min.js"></script>
Expected behavior I expect the provider is always available.
Smartphone (please complete the following information):
to be added after bug submission by internal support / PM Severity