detect-provider icon indicating copy to clipboard operation
detect-provider copied to clipboard

MetaMask detect connection does not detect my mobile MetaMask App

Open Mysth opened this issue 3 years ago • 21 comments

const detectProv = async () => {
        const provider = await detectEthereumProvider()
        let web3 = new Web3(provider)
        let chainID = await web3.eth.getChainId()
        window.alert(chainID)

        if (window.ethereum) {
            handleEthereum();
        } else {
            window.addEventListener('ethereum#initialized', handleEthereum, {
                once: true,
            });

            // If the event is not dispatched by the end of the timeout,
            // the user probably doesn't have MetaMask installed.
            setTimeout(handleEthereum, 3000); // 3 seconds
        }

        function handleEthereum() {
            const { ethereum } = window;
            if (ethereum && ethereum.isMetaMask) {
                console.log('Ethereum successfully detected!');
                window.alert("detected")
                // Access the decentralized web!
            } else {
                console.log('Please install MetaMask!');
            }
        }
    }

I try to detect my MetaMask application as the provider via a web-site using detect-provider library. In the desktop, it works fine but when I try to detect the provider using the same website and connect it to via my phone, it does not detect any provider. Where am I wrong?

Mysth avatar Aug 11 '22 13:08 Mysth

Hi @Mysth, sorry to hear about this. What do you mean you try to connect to it via your phone?

mcmire avatar Aug 12 '22 01:08 mcmire

Hi @mcmire, I want to detect the provider via the phone by connecting my dApp via browser yet I cannot detect it. I want to detect any disconnection or session ends dynamically even if the opened tab or browser is closed. Yet, I cannot detect it.

Mysth avatar Aug 12 '22 09:08 Mysth

Hi! Same issue here.

BiLosxD avatar Aug 14 '22 06:08 BiLosxD

Hi! Same issue here.

BiLosxD avatar Aug 14 '22 06:08 BiLosxD

Could it be related to lib version? Since i have same issue

vildantursic avatar Aug 24 '22 07:08 vildantursic

@Mysth When you say "browser", do you mean the browser inside of MetaMask, or is it outside?

@BiLosxD and @vildantursic When you say you have the "same issue", what issue do you mean exactly? Are you visiting your dapp within the browser inside of MetaMask or outside?

mcmire avatar Aug 24 '22 16:08 mcmire

Hi @mcmire!

Visiting the MetaMask outside.

BiLosxD avatar Aug 24 '22 16:08 BiLosxD

@BiLosxD Cool. The tl;dr here is that this won't work — you need to visit your dapp inside MetaMask. For a longer explanation, please read: https://github.com/MetaMask/detect-provider/issues/38#issuecomment-1215739459

mcmire avatar Aug 24 '22 17:08 mcmire

Hello guys, I have the same problem with metamask app on mobile. I'm in the app, spent hours testing but nothing... window.ethereum still undefined.

the event is never called

window.addEventListener("ethereum#initialized", function(event) { alert('be or not 2 be'); },{once: true});

and the provider timeout at 30sec, nothing changes always undefined

 this.provider = await detectEthereumProvider({
        'timeout':30000
  })

I thought maybe metamask changed something?

I am with a local ip, in http, containing the sslip.io and port, I tested online with an ssl and https... still nothing undefined

Someone would have any idea? PLZZZ :)


Small supplement, I have version 1.2.0, I also tested directly in the body with a setTimeout to see outside of my environment something would happen but nothing always the same ... Undefined ... I go crazy with This stupidity especially that Metamask describes it in his documentation ^^.

Yet with the desktop version, perfect, detection, signature, events, everything is fine but the mobile side seems to me more Tricky ... :)

spellet avatar Aug 30 '22 22:08 spellet

@spellet If you go on CodeSandbox, reproduce this issue there, and give us a link to your sandbox so that we can try it out too, that would help us a lot. Otherwise it's hard to say exactly why you'd be getting this error.

mcmire avatar Sep 02 '22 17:09 mcmire

Having the same problem, the detectEthereumProvider from '@metamask/detect-provider' doesn't work when using Mobile MetaMask (browser).

@mcmire here is minimal CodeSandbox to test it out https://codesandbox.io/s/clever-wave-z59g1u

It works on Firefox+Metamask extension. Doesn't work on MetaMask mobile

305670070_475614547765628_4430559615852516812_n

antonio-ivanovski avatar Sep 07 '22 10:09 antonio-ivanovski

@toteto What happens when you go directly to that URL, https://z59g1u.csb.app? For me, for some reason, opening the CodeSandbox didn't work in MetaMask mobile, but when I went to the deployed URL directly I got a "Connect to this site?" popup.

mcmire avatar Sep 08 '22 20:09 mcmire

I assume the solutions are either to continue to enhance the MetaMask Mobile Browser (which seems funny to me considering how many browsers already exists) and require that all Mobile dApps use that (a horrible UX) OR to find a way to detect and communicate to installed Mobile apps via Browser-based app logic, which is asking for quite a lot.

PureNukage avatar Sep 13 '22 16:09 PureNukage

Well, we haven't been able to reproduce any example of not being to use this library from within the mobile app yet. If we can do that then we can focus on solutions! As I alluded to above a codesandbox is the best way for us to do that as it gives us a URL we can go to directly within the mobile app to test.

mcmire avatar Sep 13 '22 18:09 mcmire

I have an HTML5 project that connects to MetaMask in Chrome on Desktop just fine, it does not connect to MetaMask on Android Mobile using Chrome (as expected) and the HTML5 project does not launch at all in the MetaMask Browser on Android (a fun surprise)

(insert Scooby-Doo hallway chase gag as a metaphor for this apps development)

PureNukage avatar Sep 13 '22 18:09 PureNukage

@PureNukage Gotcha. Are you able to recreate part of your app using CodeSandbox or some other service, or is your app opensource by chance so that I can run it locally and try it out? That would help a lot!

mcmire avatar Sep 19 '22 18:09 mcmire

Hi. Using Metamask mobile v5.6.1 I am able to reproduce this issue (both building from source in emulator and on actual device). When within the metamask browser window.ethereum is undefined.

0xdeployer avatar Sep 26 '22 21:09 0xdeployer

@toteto What happens when you go directly to that URL, https://z59g1u.csb.app? For me, for some reason, opening the CodeSandbox didn't work in MetaMask mobile, but when I went to the deployed URL directly I got a "Connect to this site?" popup.

Sorry for the delayed reply, this issue took a back-seat and missed the the notification.

You are correct, it works when accessed directly on the URL. Maybe you know why it doesn't work when accessed via the sandbox? Maybe this answer can point me in the direction on what I am doing wrong.

Will try to another minimal setup that that will reproduce this issue. Meanwhile, since the issue is live on our app on https://app.mailchain.com/, maybe you can gather more info there?

antonio-ivanovski avatar Oct 26 '22 19:10 antonio-ivanovski

Screenshot_2023-06-12-17-00-26-820

Isabelle2505 avatar Jun 12 '23 21:06 Isabelle2505

سلام @ mcmire, من می خواهم از طریق تلفن با اتصال dApp از طریق مرورگر، ارائه دهنده را شناسایی کنم، اما نمی توانم آن را تشخیص دهم. من می خواهم هر گونه قطع ارتباط را تشخیص دهم یا جلسه به صورت پویا به پایان می رسد حتی اگر برگه یا مرورگر باز شده بسته باشد. اما نمی توانم آن را تشخیص دهم.

mjraha592 avatar Nov 29 '23 14:11 mjraha592

آیا از پنل جدید و آپدیت شده استفاده میکنید لطفاً از پنل جدید استفاده کنید و کروم خود را آپدیت کنید

در تاریخ چهارشنبه ۲۹ نوامبر ۲۰۲۳،‏ ۱۸:۲۰ mjraha592 @.***> نوشت:

سلام @ mcmire, من می خواهم از طریق تلفن با اتصال dApp از طریق مرورگر، ارائه دهنده را شناسایی کنم، اما نمی توانم آن را تشخیص دهم. من می خواهم هر گونه قطع ارتباط را تشخیص دهم یا جلسه به صورت پویا به پایان می رسد حتی اگر برگه یا مرورگر باز شده بسته باشد. اما نمی توانم آن را تشخیص دهم.

— Reply to this email directly, view it on GitHub https://github.com/MetaMask/detect-provider/issues/57#issuecomment-1832041943, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXFCEWSF5ORBPOCFE4JIOGLYG5DSPAVCNFSM56IDDNX2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBTGIYDIMJZGQZQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

amimahd avatar Nov 29 '23 15:11 amimahd