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 | |
parent | 609397d95a73bdae55de41c47b19932e810d0320 (diff) |
handle changing permissions better
-rw-r--r-- | src/webex/wxBackend.ts | 37 | ||||
-rw-r--r-- | webextension/manifest.json | 4 |
2 files changed, 34 insertions, 7 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(); + }); } diff --git a/webextension/manifest.json b/webextension/manifest.json index 7592b3509..120d008c7 100644 --- a/webextension/manifest.json +++ b/webextension/manifest.json @@ -4,8 +4,8 @@ "name": "GNU Taler Wallet (git)", "description": "Privacy preserving and transparent payments", "author": "GNU Taler Developers", - "version": "0.6.75", - "version_name": "0.6.0pre10", + "version": "0.6.77.1", + "version_name": "0.7.0.dev.1", "minimum_chrome_version": "51", "minimum_opera_version": "36", |