1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Merge pull request #2352 from MetaMask/i1340-SynchronousInjection

Fix slow web3 injection bug
This commit is contained in:
kumavis 2017-10-12 13:01:29 -07:00 committed by GitHub
commit 701887bb19
3 changed files with 13 additions and 5 deletions

View File

@ -2,6 +2,8 @@
## Current Master ## Current Master
- Fix bug where web3 API was sometimes injected after the page loaded.
## 3.11.0 2017-10-11 ## 3.11.0 2017-10-11
- Add support for new eth_signTypedData method per EIP 712. - Add support for new eth_signTypedData method per EIP 712.

View File

@ -7,7 +7,9 @@ const ObjectMultiplex = require('obj-multiplex')
const extension = require('extensionizer') const extension = require('extensionizer')
const PortStream = require('./lib/port-stream.js') 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: // Eventually this streaming injection could be replaced with:
// https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Language_Bindings/Components.utils.exportFunction // https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Language_Bindings/Components.utils.exportFunction
@ -25,8 +27,7 @@ function setupInjection () {
try { try {
// inject in-page script // inject in-page script
var scriptTag = document.createElement('script') var scriptTag = document.createElement('script')
scriptTag.src = extension.extension.getURL('scripts/inpage.js') scriptTag.textContent = inpageBundle
scriptTag.textContent = inpageText
scriptTag.onload = function () { this.parentNode.removeChild(this) } scriptTag.onload = function () { this.parentNode.removeChild(this) }
var container = document.head || document.documentElement var container = document.head || document.documentElement
// append as first child // append as first child

View File

@ -186,8 +186,13 @@ jsFiles.forEach((jsFile) => {
gulp.task(`build:js:${jsFile}`, bundleTask({ watch: false, label: jsFile, filename: `${jsFile}.js` })) gulp.task(`build:js:${jsFile}`, bundleTask({ watch: false, label: jsFile, filename: `${jsFile}.js` }))
}) })
gulp.task('dev:js', gulp.parallel(...jsDevStrings)) // inpage must be built before all other scripts:
gulp.task('build:js', gulp.parallel(...jsBuildStrings)) 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 // disc bundle analyzer tasks