Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Fix testIfLoaded so it can see when a load is in progress (#2762)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianb authored and jaredhirsch committed Apr 27, 2017
1 parent 73580f0 commit c521008
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions addon/webextension/background/selectorLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ this.selectorLoader = (function() {
};

exports.testIfLoaded = function(tabId) {
if (loadingTabs.has(tabId)) {
return true;
}
return browser.tabs.executeScript(tabId, {
code: "!!this.selectorLoader",
runAt: "document_start"
Expand All @@ -57,11 +60,23 @@ this.selectorLoader = (function() {
});
};

let loadingTabs = new Set();

exports.loadModules = function(tabId, hasSeenOnboarding) {
let promise;
loadingTabs.add(tabId);
if (hasSeenOnboarding) {
return executeModules(tabId, standardScripts.concat(selectorScripts));
promise = executeModules(tabId, standardScripts.concat(selectorScripts));
} else {
promise = executeModules(tabId, standardScripts.concat(onboardingScripts).concat(selectorScripts));
}
return executeModules(tabId, standardScripts.concat(onboardingScripts).concat(selectorScripts));
return promise.then((result) => {
loadingTabs.delete(tabId);
return result;
}, (error) => {
loadingTabs.delete(tabId);
throw error;
});
};

function executeModules(tabId, scripts) {
Expand Down

0 comments on commit c521008

Please sign in to comment.