Skip to content

Commit 3adfa8c

Browse files
committed
Don't cache script-injection state when a page already has scripts
injectTranslationScripts() returned before its cleanup when a ping showed the scripts were already present, permanently caching the per-tab in-progress marker, so all later calls for the tab returned the cached promise without pinging or injecting. Chromium and Firefox inject content scripts on every page, so the skipped injection didn't matter there, but on Safari a tab can reach a page without scripts, e.g., by navigating to an ungranted site that the user then grants access to, and the on-demand injection for user actions would silently do nothing for the rest of the tab's life. Run the cleanup on every path.
1 parent 8ebe182 commit 3adfa8c

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

src/browserExt/background.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -356,12 +356,12 @@ Zotero.Connector_Browser = new function() {
356356
}
357357
deferred = Zotero.Promise.defer();
358358
this.injectTranslationScripts[key] = deferred;
359-
360-
let response = await Zotero.Messaging.sendMessage('ping', null, tab, frameId)
361-
if (response && frameId == 0) return deferred.resolve();
362-
url = url ? `${url} - ${tab.url}` : tab.url
363-
Zotero.debug(`Injecting translation scripts into ${frameId} ${url}`);
359+
364360
try {
361+
let response = await Zotero.Messaging.sendMessage('ping', null, tab, frameId)
362+
if (response && frameId == 0) return deferred.resolve();
363+
url = url ? `${url} - ${tab.url}` : tab.url
364+
Zotero.debug(`Injecting translation scripts into ${frameId} ${url}`);
365365
return await Zotero.Connector_Browser.injectScripts(_injectTranslationScripts, tab, frameId);
366366
} catch (e) {
367367
Zotero.debug(`Translation Inject: Script injection rejected ${key}`);

0 commit comments

Comments
 (0)