From a260d269ecf73005814787cc4cf9965abeb22223 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 15 Sep 2017 09:47:47 -0400 Subject: [PATCH] check for `chrome.webRequest.onAuthRequired` avail --- src/background.js | 88 ++++++++++++++++++++++++----------------------- 1 file changed, 45 insertions(+), 43 deletions(-) diff --git a/src/background.js b/src/background.js index 352d0fc94a..dba94f4cce 100644 --- a/src/background.js +++ b/src/background.js @@ -230,69 +230,71 @@ var bg_isBackground = true, } }); - chrome.webRequest.onAuthRequired.addListener(function (details, callback) { - if (!details.url || pendingAuthRequests.indexOf(details.requestId) != -1) { - if (callback) { - callback(); + if (chrome.webRequest && chrome.webRequest.onAuthRequired) { + chrome.webRequest.onAuthRequired.addListener(function (details, callback) { + if (!details.url || pendingAuthRequests.indexOf(details.requestId) != -1) { + if (callback) { + callback(); + } + return; } - return; - } - var domain = bg_utilsService.getDomain(details.url); - if (!domain) { - if (callback) { - callback(); + var domain = bg_utilsService.getDomain(details.url); + if (!domain) { + if (callback) { + callback(); + } + return; } - return; - } - pendingAuthRequests.push(details.requestId); + pendingAuthRequests.push(details.requestId); - if (bg_utilsService.isFirefox()) { - return new Promise(function (resolve, reject) { + if (bg_utilsService.isFirefox()) { + return new Promise(function (resolve, reject) { + bg_loginService.getAllDecryptedForDomain(domain).then(function (logins) { + if (!logins || logins.length !== 1) { + reject(); + return; + } + + resolve({ + authCredentials: { + username: logins[0].username, + password: logins[0].password + } + }); + }, function () { + reject(); + }); + }); + } + else { bg_loginService.getAllDecryptedForDomain(domain).then(function (logins) { if (!logins || logins.length !== 1) { - reject(); + callback(); return; } - resolve({ + callback({ authCredentials: { username: logins[0].username, password: logins[0].password } }); }, function () { - reject(); - }); - }); - } - else { - bg_loginService.getAllDecryptedForDomain(domain).then(function (logins) { - if (!logins || logins.length !== 1) { callback(); - return; - } - - callback({ - authCredentials: { - username: logins[0].username, - password: logins[0].password - } }); - }, function () { - callback(); - }); - } - }, { urls: ['http://*/*', 'https://*/*'] }, [bg_utilsService.isFirefox() ? 'blocking' : 'asyncBlocking']); + } + }, { urls: ['http://*/*', 'https://*/*'] }, [bg_utilsService.isFirefox() ? 'blocking' : 'asyncBlocking']); - chrome.webRequest.onCompleted.addListener(completeAuthRequest, { urls: ['http://*/*'] }); - chrome.webRequest.onErrorOccurred.addListener(completeAuthRequest, { urls: ['http://*/*'] }); + chrome.webRequest.onCompleted.addListener(completeAuthRequest, { urls: ['http://*/*'] }); + chrome.webRequest.onErrorOccurred.addListener(completeAuthRequest, { urls: ['http://*/*'] }); - function completeAuthRequest(details) { - var i = pendingAuthRequests.indexOf(details.requestId); - if (i > -1) { - pendingAuthRequests.splice(i, 1); + function completeAuthRequest(details) { + var i = pendingAuthRequests.indexOf(details.requestId); + if (i > -1) { + pendingAuthRequests.splice(i, 1); + } } }