Window.ethereum is not being injected on Android Metamask mobile

I have a problem with connecting to my dapp on MetaMask Android mobile app. It seems that the window.ethereum is not being injected at all.

Trying this on your IOS app, it seems to be working fine, so it seems to be an Android specific problem.

You can check out the url here: https://pendle-ui-staging.et.r.appspot.com/trade?t=mint

You will be able to see that its working fine on desktop (chrome extension), MetaMask IOS app.

So the only problem seems to be on MetaMask Android

1 Like

were you able to figure out the problem? i am also facing the same issue

Hi,

I think I have the same issue.
I’m using detect-provider from Github in my hybrid app (installed via npm i @metamask/detect-provider).
When I run my app on Chrome it works fine but when I build that for Android (native app) and deploy it on my mobile device (which has Metamask installed) I get:

@metamask/detect-provider: Unable to detect window.ethereum.

I don’t know what I have to do in order to request eth_requestAccounts on a native Android app.

If somebody figures out, please post here!

Thank you!

1 Like

I am facing the same issue.

Hello @devguto !

What version of android are you using ?
Also, what library are you interfacing with ? MetaMask-sdk or detect-provider ?

4 Likes

Hi there, i seem to be facing the same issue with ethereum not being injected on MetaMask mobile in-app browser. In my case I’m using an android device and at times ethereum does get injected but more often not. Can someone please help

Hi could you share more details pls

Hi there, yes, the window.etheruem object gets injected but ay times get unloaded. On my android device I have installed MetaMask. I open its in app browser and type my applications site. On the click of a button where i need to trigger MetaMask, window.ethereum at times gets injected but most often not. window.ethereum comes up as ‘undefined’. I tried setting a higher timeout but nothing happens. I looked into all solutions provided on stackoverflow, MetaMask github and other and tired taking out heavy tags in , setting timeouts, adding listeners but nothing seemed to solve the issue. Is there a workaround this? and why does the injection happen on and off?

Any insights on this ?

It’s an old topic, could you share what is the issue? Do you have the same any details would be helpful

Same issue, running below html via ngrok works in browser extension and macOS app, however android fails to detect windows.ethereum.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MetaMask Test</title>
</head>
<body>
    <h1>MetaMask Injection Test</h1>
    <script>
        document.addEventListener('DOMContentLoaded', () => {
            console.log('window.ethereum:', window.ethereum);
            if (window.ethereum) {
                alert('MetaMask is available!');
            } else {
                alert('MetaMask is not available!');
            }
        });
    </script>
</body>
</html>

@user964 looks like there is an existing issue: window.ethereum undefined on mobile? · Issue #3503 · MetaMask/metamask-mobile · GitHub have you seen it?