diff --git a/CHANGELOG.md b/CHANGELOG.md index ab5b3cb9f..65f75ee18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Current Master +- Fix bug where web3 API was sometimes injected after the page loaded. + ## 3.11.0 2017-10-11 - Add support for new eth_signTypedData method per EIP 712. diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js index b4708189e..ffbbc73cc 100644 --- a/app/scripts/contentscript.js +++ b/app/scripts/contentscript.js @@ -7,7 +7,9 @@ const ObjectMultiplex = require('obj-multiplex') const extension = require('extensionizer') const PortStream = require('./lib/port-stream.js') -const inpageText = fs.readFileSync(path.join(__dirname, 'inpage.js')).toString() +const inpageContent = fs.readFileSync(path.join(__dirname, '..', '..', 'dist', 'chrome', 'scripts', 'inpage.js')).toString() +const inpageSuffix = '//# sourceURL=' + extension.extension.getURL('scripts/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 @@ -25,8 +27,7 @@ function setupInjection () { try { // inject in-page script var scriptTag = document.createElement('script') - scriptTag.src = extension.extension.getURL('scripts/inpage.js') - scriptTag.textContent = inpageText + scriptTag.textContent = inpageBundle scriptTag.onload = function () { this.parentNode.removeChild(this) } var container = document.head || document.documentElement // append as first child diff --git a/gulpfile.js b/gulpfile.js index 557b58a68..9253949c7 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -186,8 +186,13 @@ jsFiles.forEach((jsFile) => { gulp.task(`build:js:${jsFile}`, bundleTask({ watch: false, label: jsFile, filename: `${jsFile}.js` })) }) -gulp.task('dev:js', gulp.parallel(...jsDevStrings)) -gulp.task('build:js', gulp.parallel(...jsBuildStrings)) +// inpage must be built before all other scripts: +const firstDevString = jsDevStrings.shift() +gulp.task('dev:js', gulp.series(firstDevString, gulp.parallel(...jsDevStrings))) + +// inpage must be built before all other scripts: +const firstBuildString = jsBuildStrings.shift() +gulp.task('build:js', gulp.series(firstBuildString, gulp.parallel(...jsBuildStrings))) // disc bundle analyzer tasks