aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/contentscript.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/scripts/contentscript.js')
-rw-r--r--app/scripts/contentscript.js33
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(){