brave / brave-browser

Brave browser for Android, iOS, Linux, macOS, Windows.
https://brave.com
Mozilla Public License 2.0
17.51k stars 2.26k forks source link

Can't detect new built-in "crypto wallets" extension of brave browser in javascript #7166

Open ppeinsold opened 4 years ago

ppeinsold commented 4 years ago

Description

In javascript there is no "window.ethereum" or "window.web3" available if only crypto wallets is enabled and metamask is not installed. Do you maybe inject a different variable? As long as the MetaMask extension is installed the window.ethereum property is existing and otherwise not. I've also checked if the native wallet of Brave and its API is documented somewhere but I sadly couldn't find any documentation about it.

Steps to Reproduce

Let me add a little bit of a code example. The following code is to connect to web3 browser using web3js library:

        // Check for injected web3 (mist/metamask)             
        // Modern dapp browsers...
        let web3Provider = null;
        if (window.ethereum) {
            web3Provider = window.ethereum;
            try {
                // Request account access
                await window.ethereum.enable();
            } catch (error) {
                // User denied account access...
                console.error("User denied account access to metamask");
                return;
            }
        }
        // Legacy dapp browsers...
        else if (window.web3) {
            web3Provider = window.web3.currentProvider;
        }
        else {
            console.error("Unable to connect to metamask");
            return;
        }

        let web3 = new Web3(web3Provider);
        ...

Actual result:

This works fine for all browsers but in brave it crashes when "crypto wallets" is enabled. The problem here is, that a check is missing. On the line where I have " console.error("Unable to connect to metamask");" I need to detect "crypto wallets" because I end up here if only "crypto wallets" is installed and metamask is not. Does anyone know how to make this check?

Expected result:

We can detect built-in "crypto wallets"-extension of brave browser with an injected variable.

Reproduces how often:

Easily reproduced

Brave version (brave://version info)

newest brave version

ppeinsold commented 4 years ago

@bsclifton why do you label that as "feature". It is clearly a bug imo. We also tested it with a lot of dapps and it breaks every single one of them.

srirambv commented 4 years ago

@ppeinsold The label is for internal use to triage the issues relating to Crypto Wallets. I have added the appropriate labels

sisou commented 4 years ago

I am stumbling about this now. I found that Brave has a setting under Settings/Extensions called "Web3 provider for using Dapps". By default, it is set to "Ask": image

When set like this, I cannot detect window.web3 or window.ethereum on any page. Only when set to the "Crypto Wallets" setting, these global objects become available.

My question is now: How do I "Ask" Brave for these APIs on a per-website basis?

aishv123 commented 3 years ago

Was the bug resolved, Could somebody please guide me the link if an API exists to connect to crypto wallet