diff --git a/gulpfile.js b/gulpfile.js index 80910fa36f..d341128470 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -226,6 +226,8 @@ function processFile() { file.contents = Buffer.from(file.contents.toString() .replace("/*BACKGROUND SCRIPTS*/", backgroundInclude.map((s) => `"${s}"`).join(',\n\t\t\t')) + .replace("/*INJECT SCRIPTS*/", + injectIncludeBrowserExt.map((s) => `"${s}"`).join(',\n\t\t')) .replace(/"version": "[^"]*"/, '"version": "'+argv.version+'"')); break; case 'script-injection.js': diff --git a/src/browserExt/background.js b/src/browserExt/background.js index 1d7d5864c8..676bf0e77b 100644 --- a/src/browserExt/background.js +++ b/src/browserExt/background.js @@ -358,7 +358,7 @@ Zotero.Connector_Browser = new function() { browser.webNavigation.onCommitted.addListener(logListenerErrors(async function(details) { var tab = await browser.tabs.get(details.tabId); // Ignore developer tools - if (tab.id < 0 || _isDisabledForURL(tab.url, true)) return; + if (tab.id < 0 || Zotero.Connector_Browser.isDisabledForURL(tab.url, true)) return; if (details.frameId == 0) { // Ignore item selector diff --git a/src/browserExt/script-injection.js b/src/browserExt/script-injection.js index 884bb4551e..b54537248c 100644 --- a/src/browserExt/script-injection.js +++ b/src/browserExt/script-injection.js @@ -42,7 +42,7 @@ Zotero.Extension.ScriptInjection = { let key = tab.id+'-'+frameId; let deferred = this.injectTranslationScripts[key]; if (deferred) { - Zotero.debug(`Extension.ScriptInjection.injectTranslationScripts: Script injection already in progress for ${key} : ${tab.url}`); + Zotero.debug(`Translation Inject: Script injection already in progress for ${key}`); return deferred.promise; } deferred = Zotero.Promise.defer(); @@ -52,13 +52,14 @@ Zotero.Extension.ScriptInjection = { Zotero.debug(`Translation Inject: Script injection rejected ${key}`); Zotero.debug(e.message); }).then(function() { - delete Zotero.Connector_Browser.injectTranslationScripts[key]; + delete Zotero.Extension.ScriptInjection.injectTranslationScripts[key]; }); Zotero.Messaging.sendMessage('ping', null, tab, frameId).then(function(response) { if (response && frameId == 0) return deferred.resolve(); Zotero.debug(`Injecting translation scripts into ${frameId} ${tab.url}`); - return Zotero.Connector_Browser.injectScripts(_injectTranslationScripts, tab, frameId) + return Zotero.Connector_Browser.injectScripts( + Zotero.Extension.ScriptInjection._translationScriptList, tab, frameId) .then(deferred.resolve).catch(deferred.reject); }); return deferred.promise; @@ -114,8 +115,8 @@ Zotero.Extension.ScriptInjection = { var timedOut = Zotero.Promise.defer(); let timeout = setTimeout(function() { - timedOut.reject(new Error (`Inject: Timed out ${frameId} - ${tab.url} after ${this.INJECTION_TIMEOUT}ms`)) - }.bind(this), this.INJECTION_TIMEOUT); + timedOut.reject(new Error (`Inject: Timed out ${frameId} - ${tab.url} after ${Zotero.Extension.ScriptInjection.INJECTION_TIMEOUT}ms`)) + }, Zotero.Extension.ScriptInjection.INJECTION_TIMEOUT); // Prevent triggering multiple times let deferred = Zotero.Connector_Browser._tabInfo[tab.id].injections[frameId]; @@ -153,7 +154,7 @@ Zotero.Extension.ScriptInjection = { } finally { browser.tabs.onRemoved.removeListener(tabRemovedListener); deferred.resolve(); - delete _tabInfo[tab.id].injections[frameId]; + delete Zotero.Connector_Browser._tabInfo[tab.id].injections[frameId]; clearTimeout(timeout); } } diff --git a/src/browserExt/test/testSetup.js b/src/browserExt/test/testSetup.js index 39208e0d37..b5e49c1219 100644 --- a/src/browserExt/test/testSetup.js +++ b/src/browserExt/test/testSetup.js @@ -106,7 +106,7 @@ Zotero.initDeferred.promise.then(function() { let scripts = [ 'lib/sinon.js', 'test/testSetup.js' ]; try { - await Zotero.Extension.injectScripts(scripts, tab); + await Zotero.Connector_Browser.injectScripts(scripts, tab); deferred.resolved = true; deferred.resolve(tab.id); } catch(e) { @@ -152,6 +152,10 @@ if (typeof mocha != 'undefined') { var deferred = Zotero.Promise.defer(); var tab = await browser.tabs.create({url, active: false}); Zotero.Background.registeredTabs[tab.id] = deferred; + Zotero.Connector_Browser._tabInfo[tab.id] = { + url: url, + injections: {} + }; return deferred.promise; }, url); }),