diff options
author | Kevin Serrano <kevgagser@gmail.com> | 2016-07-27 14:32:12 +0800 |
---|---|---|
committer | Kevin Serrano <kevgagser@gmail.com> | 2016-07-27 14:32:12 +0800 |
commit | cf14eb4043865e26e13009f813b71f80203bf847 (patch) | |
tree | db1a4511ff4dab29c82940965223002202336bc6 /app/scripts/contentscript.js | |
parent | 3a4744dec179d0845cd9a3c306a6318dd609f4bd (diff) | |
parent | 7a8d0497324f6f05274e7ffeef828134cbf9c481 (diff) | |
download | tangerine-wallet-browser-cf14eb4043865e26e13009f813b71f80203bf847.tar tangerine-wallet-browser-cf14eb4043865e26e13009f813b71f80203bf847.tar.gz tangerine-wallet-browser-cf14eb4043865e26e13009f813b71f80203bf847.tar.bz2 tangerine-wallet-browser-cf14eb4043865e26e13009f813b71f80203bf847.tar.lz tangerine-wallet-browser-cf14eb4043865e26e13009f813b71f80203bf847.tar.xz tangerine-wallet-browser-cf14eb4043865e26e13009f813b71f80203bf847.tar.zst tangerine-wallet-browser-cf14eb4043865e26e13009f813b71f80203bf847.zip |
Merge branch 'master' into droppo-fix
Diffstat (limited to 'app/scripts/contentscript.js')
-rw-r--r-- | app/scripts/contentscript.js | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js index 0ffe93e3c..1eb04059d 100644 --- a/app/scripts/contentscript.js +++ b/app/scripts/contentscript.js @@ -3,19 +3,37 @@ const PortStream = require('./lib/port-stream.js') const ObjectMultiplex = require('./lib/obj-multiplex') const extension = require('./lib/extension') +const fs = require('fs') +const path = require('path') +const inpageText = fs.readFileSync(path.join(__dirname + '/inpage.js')).toString() + +// Eventually this streaming injection could be replaced with: +// https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Language_Bindings/Components.utils.exportFunction +// +// But for now that is only Firefox +// If we create a FireFox-only code path using that API, +// MetaMask will be much faster loading and performant on Firefox. + if (shouldInjectWeb3()) { setupInjection() setupStreams() } function setupInjection(){ - // inject in-page script - var scriptTag = document.createElement('script') - scriptTag.src = extension.extension.getURL('scripts/inpage.js') - scriptTag.onload = function () { this.parentNode.removeChild(this) } - var container = document.head || document.documentElement - // append as first child - container.insertBefore(scriptTag, container.children[0]) + try { + + // inject in-page script + var scriptTag = document.createElement('script') + scriptTag.src = extension.extension.getURL('scripts/inpage.js') + scriptTag.textContent = inpageText + scriptTag.onload = function () { this.parentNode.removeChild(this) } + var container = document.head || document.documentElement + // append as first child + container.insertBefore(scriptTag, container.children[0]) + + } catch (e) { + console.error('Metamask injection failed.', e) + } } function setupStreams(){ @@ -44,7 +62,6 @@ function setupStreams(){ pluginStream.on('close', function () { reloadStream.write({ method: 'reset' }) }) - } function shouldInjectWeb3(){ |