From cf9d71051f754c54e42b106277343f6adc199c49 Mon Sep 17 00:00:00 2001 From: "Brian R. Bondy" Date: Wed, 15 Jan 2020 16:28:27 -0500 Subject: [PATCH] Compat w/ Brave to support multi web3 providers This implements the spec changes needed for better compatibility with Brave: brave/brave-browser#7503 It makes it so both extensions can co-exist. --- app/scripts/contentscript.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js index 8b2040b16e7f..0472cf25decd 100644 --- a/app/scripts/contentscript.js +++ b/app/scripts/contentscript.js @@ -1,3 +1,5 @@ +/*global chrome*/ + import pump from 'pump' import querystring from 'querystring' import LocalMessageDuplexStream from 'post-message-stream' @@ -21,8 +23,19 @@ const inpageBundle = inpageContent + inpageSuffix // MetaMask will be much faster loading and performant on Firefox. if (shouldInjectProvider()) { - injectScript(inpageBundle) - start() + // If this is Brave, it requires coordination to know if we should be the + // web3 provider. + if (chrome.braveWallet && chrome.braveWallet.getWeb3Provider) { + chrome.braveWallet.getWeb3Provider((provider) => { + if (provider === extension.runtime.id) { + injectScript(inpageBundle) + start() + } + }) + } else { + injectScript(inpageBundle) + start() + } } /**