diff options
author | Chen Wei <chenwei@byzantine-lab.io> | 2019-07-18 16:57:03 +0800 |
---|---|---|
committer | Chen Wei <chenwei@byzantine-lab.io> | 2019-07-18 16:57:03 +0800 |
commit | 94641d1443e8e680fe13e69044629ccd9ebebad6 (patch) | |
tree | cb30ccf4a233dfdad98644720c60cacde8b1ea5b | |
parent | 72099b5836825e4423a52734e521663ba939238f (diff) | |
download | tangerine-wallet-browser-94641d1443e8e680fe13e69044629ccd9ebebad6.tar tangerine-wallet-browser-94641d1443e8e680fe13e69044629ccd9ebebad6.tar.gz tangerine-wallet-browser-94641d1443e8e680fe13e69044629ccd9ebebad6.tar.bz2 tangerine-wallet-browser-94641d1443e8e680fe13e69044629ccd9ebebad6.tar.lz tangerine-wallet-browser-94641d1443e8e680fe13e69044629ccd9ebebad6.tar.xz tangerine-wallet-browser-94641d1443e8e680fe13e69044629ccd9ebebad6.tar.zst tangerine-wallet-browser-94641d1443e8e680fe13e69044629ccd9ebebad6.zip |
do not load inpage.js by "fs". They can be accessed with extension URL
-rw-r--r-- | app/scripts/contentscript.js | 17 | ||||
-rw-r--r-- | app/scripts/inpage.js | 29 |
2 files changed, 9 insertions, 37 deletions
diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js index aa9f51d0e..2a47784ed 100644 --- a/app/scripts/contentscript.js +++ b/app/scripts/contentscript.js @@ -1,5 +1,3 @@ -const fs = require('fs') -const path = require('path') const pump = require('pump') const log = require('loglevel') const Dnode = require('dnode') @@ -8,10 +6,13 @@ const LocalMessageDuplexStream = require('post-message-stream') const ObjectMultiplex = require('obj-multiplex') const extension = require('extensionizer') const PortStream = require('extension-port-stream') +// const injectedScript = require('./inpage_stringify') -const inpageContent = fs.readFileSync(path.join(__dirname, '..', '..', 'dist', 'chrome', 'inpage.js')).toString() -const inpageSuffix = '//# sourceURL=' + extension.extension.getURL('inpage.js') + '\n' -const inpageBundle = inpageContent + inpageSuffix +// console.log(`typeof(injectedScript)`, typeof injectedScript) + +// const inpageContent = fs.readFileSync(path.join(__dirname, '..', '..', 'dist', 'chrome', 'inpage.js')).toString() +// const inpageSuffix = '//# sourceURL=' + extension.extension.getURL('inpage.js') + '\n' +// const inpageBundle = inpageContent + inpageSuffix // Eventually this streaming injection could be replaced with: // https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Language_Bindings/Components.utils.exportFunction @@ -21,7 +22,7 @@ const inpageBundle = inpageContent + inpageSuffix // MetaMask will be much faster loading and performant on Firefox. if (shouldInjectWeb3()) { - injectScript(inpageBundle) + injectScript() start() } @@ -30,12 +31,12 @@ if (shouldInjectWeb3()) { * * @param {string} content - Code to be executed in the current document */ -function injectScript (content) { +function injectScript () { try { const container = document.head || document.documentElement const scriptTag = document.createElement('script') scriptTag.setAttribute('async', false) - scriptTag.textContent = content + scriptTag.src = extension.extension.getURL('inpage.js') container.insertBefore(scriptTag, container.children[0]) // container.removeChild(scriptTag) } catch (e) { diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js index 705741cf1..365d4c53e 100644 --- a/app/scripts/inpage.js +++ b/app/scripts/inpage.js @@ -115,14 +115,6 @@ window.tangerine = createStandardProvider(proxiedInpageProvider) // setup web3 // -// if (typeof window.web3 !== 'undefined') { -// throw new Error(`MetaMask detected another web3. -// MetaMask will not work reliably with another web3 extension. -// This usually happens if you have two MetaMasks installed, -// or MetaMask and another web3 extension. Please remove one -// and try again.`) -// } - const web3 = new Web3(proxiedInpageProvider) web3.setProvider = function () { log.debug('MetaMask - overrode web3.setProvider') @@ -131,27 +123,6 @@ log.debug('MetaMask - injected web3') setupDappAutoReload(web3, inpageProvider.publicConfigStore) -// export global web3, with usage-detection and deprecation warning - -/* TODO: Uncomment this area once auto-reload.js has been deprecated: -let hasBeenWarned = false -global.web3 = new Proxy(web3, { - get: (_web3, key) => { - // show warning once on web3 access - if (!hasBeenWarned && key !== 'currentProvider') { - console.warn('MetaMask: web3 will be deprecated in the near future in favor of the ethereumProvider \nhttps://github.com/MetaMask/faq/blob/master/detecting_metamask.md#web3-deprecation') - hasBeenWarned = true - } - // return value normally - return _web3[key] - }, - set: (_web3, key, value) => { - // set value normally - _web3[key] = value - }, -}) -*/ - // set web3 defaultAccount inpageProvider.publicConfigStore.subscribe(function (state) { web3.eth.defaultAccount = state.selectedAddress |