From 1cba6543a42561c6691736d58f45e97f4832912b Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 4 Oct 2017 15:35:04 -0700 Subject: [PATCH 1/4] Begin implementing sync injection idea --- app/scripts/contentscript.js | 3 +-- gulpfile.js | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js index b4708189e..59e7f08ce 100644 --- a/app/scripts/contentscript.js +++ b/app/scripts/contentscript.js @@ -7,7 +7,7 @@ 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 inpageText = fs.readFileSync(path.join(__dirname, '..', '..', 'dist', 'chrome', 'scripts', 'inpage.js')).toString() + '//# sourceURL=' + extension.extension.getURL('scripts/inpage.js') + '\n' // Eventually this streaming injection could be replaced with: // https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Language_Bindings/Components.utils.exportFunction @@ -25,7 +25,6 @@ function setupInjection () { 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 diff --git a/gulpfile.js b/gulpfile.js index ac36cf983..14e26ed2e 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -186,8 +186,8 @@ 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)) +gulp.task('dev:js', gulp.series(jsDevStrings.shift(), gulp.parallel(...jsDevStrings))) +gulp.task('build:js', gulp.series(jsBuildStrings.shift(), gulp.parallel(...jsBuildStrings))) // disc bundle analyzer tasks From d71f14cb678b48b8666e6835c025ff14193acbb3 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 12 Oct 2017 14:03:42 -0400 Subject: [PATCH 2/4] Increase build readability --- gulpfile.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 6d2ff5fdd..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.series(jsDevStrings.shift(), gulp.parallel(...jsDevStrings))) -gulp.task('build:js', gulp.series(jsBuildStrings.shift(), 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 From c9a984a237ccacf8994e6c4c2f49b7a17da92d6b Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 12 Oct 2017 14:16:40 -0400 Subject: [PATCH 3/4] Break up inpage file read into multiple lines --- app/scripts/contentscript.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js index 59e7f08ce..445608214 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, '..', '..', 'dist', 'chrome', 'scripts', 'inpage.js')).toString() + '//# sourceURL=' + extension.extension.getURL('scripts/inpage.js') + '\n' +const inpagePath = path.join(__dirname, '..', '..', 'dist', 'chrome', 'scripts', 'inpage.js') +const inpageString = fs.readFileSync(inpagePath).toString() +const inpageText = inpageString + '//# sourceURL=' + extension.extension.getURL('scripts/inpage.js') + '\n' // Eventually this streaming injection could be replaced with: // https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Language_Bindings/Components.utils.exportFunction From 53a360b65d6b97fa4551c2953072a21cbe9f708d Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 12 Oct 2017 12:51:48 -0700 Subject: [PATCH 4/4] contentscript - fix inpage require and bundling --- app/scripts/contentscript.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js index 445608214..ffbbc73cc 100644 --- a/app/scripts/contentscript.js +++ b/app/scripts/contentscript.js @@ -7,9 +7,9 @@ const ObjectMultiplex = require('obj-multiplex') const extension = require('extensionizer') const PortStream = require('./lib/port-stream.js') -const inpagePath = path.join(__dirname, '..', '..', 'dist', 'chrome', 'scripts', 'inpage.js') -const inpageString = fs.readFileSync(inpagePath).toString() -const inpageText = inpageString + '//# sourceURL=' + extension.extension.getURL('scripts/inpage.js') + '\n' +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 @@ -27,7 +27,7 @@ function setupInjection () { try { // inject in-page script var scriptTag = document.createElement('script') - scriptTag.textContent = inpageText + scriptTag.textContent = inpageBundle scriptTag.onload = function () { this.parentNode.removeChild(this) } var container = document.head || document.documentElement // append as first child