1
const openInstallPage = () => {
  const md = new MobileDetect(navigator.userAgent);
  if (md.is("iPhone")) {
    window.open(
      "https://apps.apple.com/us/app/metamask-blockchain-wallet/id1438144202"
    );
  } else if (md.os() || md.mobile()) {
    try {
      window.open(
        "https://metamask.app.link/dapp/emirpreview.vercel.app" //deeplink, this url will try to open metamask mobile app. If it cant, i want to redirect user to install page.
      );
    } catch (err) {
      window.open("https://play.google.com/store/apps/details?id=io.metamask");
    }
  } else {
    window.open(
      "https://chrome.google.com/webstore/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn"
    );
  }
};

When someone click my button on mobile, i want to redirect user to the metamask app if its installed. If it's not i want to redirect user to metamask install page.

How can i handle this? Try catch methods are not working at all... Am i doing something wrong?

Note: i want to do this things on mobile so im using mobile-deteck package from npm.

questiontoansw
  • 307
  • 5
  • 17
  • You're assuming `window.open` will throw an error if the URL can't be opened, that's not the case. See https://developer.mozilla.org/en-US/docs/Web/API/Window/open. – juliomalves Mar 13 '22 at 17:59
  • Yes i know it cant be done with try catch methods because window.open now throwing anything in this case. So my question is how can i learn if my user can't go to the link correctly or not? – questiontoansw Mar 13 '22 at 18:58

0 Answers0