MetaMask / extension-provider

A module for allowing a WebExtension to access the web3 provider from an installed MetaMask instance
MIT License
68 stars 28 forks source link

How to know if Metamask is already installed? #9

Closed Jack-Works closed 4 years ago

Tedko commented 4 years ago

Clipboard - 2020年8月18日下午4点53分 Right now finished the integration. however within our extension we have no idea whether user install MetaMask already or not. @danfinlay any good idea? Many thanks

brad-decker commented 4 years ago

I would recommend using our onboarding library for these purposes. Examples can be seen here

Tedko commented 4 years ago

Hi @brad-decker .

We already noticed onboarding library. However Metamask cannot inject js into another extension's page ( something like chrome-extension://jkoeaghipilijlahjplgbfiocjhldnap/index.html#/wallets )

That's why we're wondering if there's any solution.

Tedko commented 4 years ago

injecting js into another extension's page is not allowed by browser. There're other browser APIs could do so (some communication between extensions)

Right now we already able to use MetaMask inside Maskbook extension, and then provide MetaMask func on fb/Twitter. The only problem is within the extension's html page we don't know whether users installed Maskbook or not

Jack-Works commented 4 years ago

I'm afraid the onboarding library doesn't work for another web extension.

https://github.com/MetaMask/metamask-onboarding/blob/master/src/index.ts#L154

In this line, you detect metamask by window.ethereum.isMetaMask but window.ethereum is not available in the web extension. This is why I'm using extension-provider`(this library)

Tedko commented 4 years ago

Hi @brad-decker - any thoughts?

neruthes commented 4 years ago

I have been wondering whether this way is going to work.

If MetaMask is installed:

If MetaMask is not installed:

danfinlay commented 4 years ago

You should also be able to detect whether MetaMask is installed using the error event we have on this library's provider:

const createMetaMaskProvider = require('metamask-extension-provider')

const provider = createMetaMaskProvider()

provider.on('error', (error) => {
  // Failed to connect to MetaMask, likely MetaMask is not installed.
})
Tedko commented 4 years ago

@danfinlay thx it seems working well now :) @Jack-Works should we close this? would be great if you can make a document of this @danfinlay

Jack-Works commented 4 years ago

Yeah I think we can close this now

Tedko commented 4 years ago

🎭 Thx for all 🦊❤️