aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md14
-rw-r--r--app/scripts/contentscript.js33
-rw-r--r--app/scripts/lib/extension-instance.js7
-rw-r--r--gulpfile.js2
-rw-r--r--package.json1
5 files changed, 43 insertions, 14 deletions
diff --git a/README.md b/README.md
index 34fac137c..59d52b6f1 100644
--- a/README.md
+++ b/README.md
@@ -45,6 +45,20 @@ Click `Select`.
You now have the plugin, and can click 'inspect views: background plugin' to view its dev console.
+#### In Firefox (Developer Edition Only)
+
+Go to the url `about:debugging`.
+
+Click the button `Load Temporary Add-On`.
+
+Select the file `dist/manifest.json`.
+
+You can optionally enable debugging, and click `Debug`, for a console window that logs all of Metamask's processes to a single console.
+
+If you have problems debugging, try connecting to the IRC channel `#webextensions` on `irc.mozilla.org`.
+
+For longer questions, use the StackOverfow tag `firefox-addons`.
+
### Developing on UI Only
You can run `npm run ui`, and your browser should open a live-reloading demo version of the plugin UI.
diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js
index 0ffe93e3c..103ea5348 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(__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(){
diff --git a/app/scripts/lib/extension-instance.js b/app/scripts/lib/extension-instance.js
index eeab6c6d0..e0e7c948b 100644
--- a/app/scripts/lib/extension-instance.js
+++ b/app/scripts/lib/extension-instance.js
@@ -24,14 +24,9 @@ const apis = [
function Extension () {
const _this = this
- let global = window
-
- if (window.chrome) {
- global = window.chrome
- }
apis.forEach(function (api) {
- _this[api] = global[api]
+ _this[api] = chrome ? chrome[api] : window[api] || browser.extension[api]
})
}
diff --git a/gulpfile.js b/gulpfile.js
index 941155ff4..e10a4eb7d 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -8,6 +8,7 @@ var watch = require('gulp-watch')
var sourcemaps = require('gulp-sourcemaps')
var assign = require('lodash.assign')
var livereload = require('gulp-livereload')
+var brfs = require('gulp-brfs')
var del = require('del')
var eslint = require('gulp-eslint')
var fs = require('fs')
@@ -144,6 +145,7 @@ function bundleTask(opts) {
// log errors if they happen
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
.pipe(source(opts.filename))
+ .pipe(brfs())
// optional, remove if you don't need to buffer file contents
.pipe(buffer())
// optional, remove if you dont want sourcemaps
diff --git a/package.json b/package.json
index ef570fb94..1691f769a 100644
--- a/package.json
+++ b/package.json
@@ -86,6 +86,7 @@
"deep-freeze-strict": "^1.1.1",
"del": "^2.2.0",
"gulp": "github:gulpjs/gulp#4.0",
+ "gulp-brfs": "^0.1.0",
"gulp-livereload": "^3.8.1",
"gulp-sourcemaps": "^1.6.0",
"gulp-util": "^3.0.7",