Skip to content
Snippets Groups Projects
Verified Commit 6ea540fd authored by Thomas Rientjes's avatar Thomas Rientjes
Browse files

Improve active tab determination logic

parent 058cc7f8
No related branches found
No related tags found
No related merge requests found
......@@ -149,6 +149,28 @@ helpers.generateRandomHexString = function (length) {
return randomHexString;
};
helpers.determineActiveTab = function () {
return new Promise((resolve) => {
let queryParameters = {'active': true, 'currentWindow': true};
chrome.tabs.query(queryParameters, function (tabs) {
if (tabs[0]) {
resolve(tabs[0]);
} else {
queryParameters = {'active': true};
chrome.tabs.query(queryParameters, function (tabs) {
resolve(tabs[0]);
});
}
});
});
};
helpers.determineCdnName = function (domainName) {
switch (domainName) {
......
......@@ -209,10 +209,10 @@ popup._determineTargetTab = function () {
return new Promise((resolve) => {
chrome.tabs.query({'active': true, 'currentWindow': true}, function (tabs) {
helpers.determineActiveTab().then((activeTab) => {
popup._targetTab = tabs[0];
popup._domain = helpers.extractDomainFromUrl(tabs[0].url, true);
popup._targetTab = activeTab;
popup._domain = helpers.extractDomainFromUrl(activeTab.url, true);
resolve();
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment