diff options
author | Florian Dold <florian.dold@gmail.com> | 2020-05-01 15:04:12 +0530 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2020-05-01 15:04:12 +0530 |
commit | 848f44733e1e1a1b9215811e3949fca6b6e93968 (patch) | |
tree | e937bf77f3626634dfe3bf403f7c5f9fe12cec29 /src/webex | |
parent | 609397d95a73bdae55de41c47b19932e810d0320 (diff) |
handle changing permissions better
Diffstat (limited to 'src/webex')
-rw-r--r-- | src/webex/wxBackend.ts | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/src/webex/wxBackend.ts b/src/webex/wxBackend.ts index 17e5215f4..7966bbe25 100644 --- a/src/webex/wxBackend.ts +++ b/src/webex/wxBackend.ts @@ -498,6 +498,7 @@ try { function headerListener( details: chrome.webRequest.WebResponseHeadersDetails, ): chrome.webRequest.BlockingResponse | undefined { + console.log("header listener"); if (chrome.runtime.lastError) { console.error(chrome.runtime.lastError); return; @@ -507,6 +508,7 @@ function headerListener( console.warn("wallet not available while handling header"); return; } + console.log("in header listener"); if (details.statusCode === 402 || details.statusCode === 202) { console.log(`got 402/202 from ${details.url}`); for (const header of details.responseHeaders || []) { @@ -572,12 +574,29 @@ function headerListener( } function setupHeaderListener(): void { + console.log("setting up header listener"); // Handlers for catching HTTP requests - chrome.webRequest.onHeadersReceived.addListener( - headerListener, - { urls: ["https://*/*", "http://*/*"] }, - ["responseHeaders", "blocking"], - ); + chrome.permissions.contains(extendedPermissions, (result: boolean) => { + if ( + chrome.webRequest.onHeadersReceived && + chrome.webRequest.onHeadersReceived.hasListener(headerListener) + ) { + chrome.webRequest.onHeadersReceived.removeListener(headerListener); + } + if (result) { + console.log("actually adding listener"); + chrome.webRequest.onHeadersReceived.addListener( + headerListener, + { urls: ["<all_urls>"] }, + ["responseHeaders", "blocking"], + ); + } + chrome.webRequest.handlerBehaviorChanged(() => { + if (chrome.runtime.lastError) { + console.error(chrome.runtime.lastError); + } + }); + }); } /** @@ -602,4 +621,12 @@ export async function wxMain(): Promise<void> { }); setupHeaderListener(); + + chrome.permissions.onAdded.addListener((perm) => { + if (chrome.runtime.lastError) { + console.error(chrome.runtime.lastError); + return; + } + setupHeaderListener(); + }); } |