diff options
Diffstat (limited to 'packages/taler-wallet-webextension/src')
-rw-r--r-- | packages/taler-wallet-webextension/src/platform/chrome.ts | 91 | ||||
-rw-r--r-- | packages/taler-wallet-webextension/src/platform/firefox.ts | 2 |
2 files changed, 50 insertions, 43 deletions
diff --git a/packages/taler-wallet-webextension/src/platform/chrome.ts b/packages/taler-wallet-webextension/src/platform/chrome.ts index 7f384f7d4..20cf54035 100644 --- a/packages/taler-wallet-webextension/src/platform/chrome.ts +++ b/packages/taler-wallet-webextension/src/platform/chrome.ts @@ -728,19 +728,21 @@ type HeaderListenerFunc = ( ) => void; let currentHeaderListener: HeaderListenerFunc | undefined = undefined; -type TabListenerFunc = (tabId: number, info: chrome.tabs.TabChangeInfo) => void; -let currentTabListener: TabListenerFunc | undefined = undefined; +// type TabListenerFunc = (tabId: number, info: chrome.tabs.TabChangeInfo) => void; +// let currentTabListener: TabListenerFunc | undefined = undefined; function containsTalerHeaderListener(): boolean { return ( - currentHeaderListener !== undefined || currentTabListener !== undefined + currentHeaderListener !== undefined + // || currentTabListener !== undefined ); } function headerListener( details: chrome.webRequest.WebResponseHeadersDetails, ): chrome.webRequest.BlockingResponse | undefined { + logger.info("header listener run", details.statusCode, chrome.runtime.lastError) if (chrome.runtime.lastError) { logger.error(JSON.stringify(chrome.runtime.lastError)); return; @@ -784,20 +786,24 @@ function parseTalerUriAndRedirect(tabId: number, maybeTalerUri: string): void { ); } -async function tabListener( - tabId: number, - info: chrome.tabs.TabChangeInfo, -): Promise<void> { - if (tabId < 0) return; - const tabLocationHasBeenUpdated = info.status === "complete"; - const tabTitleHasBeenUpdated = info.title !== undefined; - if (tabLocationHasBeenUpdated || tabTitleHasBeenUpdated) { - const uri = await findTalerUriInTab(tabId); - if (!uri) return; - logger.info(`Found a Taler URI in the tab ${tabId}`); - parseTalerUriAndRedirect(tabId, uri); - } -} +/** + * Not needed anymore since SPA use taler support + */ + +// async function tabListener( +// tabId: number, +// info: chrome.tabs.TabChangeInfo, +// ): Promise<void> { +// if (tabId < 0) return; +// const tabLocationHasBeenUpdated = info.status === "complete"; +// const tabTitleHasBeenUpdated = info.title !== undefined; +// if (tabLocationHasBeenUpdated || tabTitleHasBeenUpdated) { +// const uri = await findTalerUriInTab(tabId); +// if (!uri) return; +// logger.info(`Found a Taler URI in the tab ${tabId}`); +// parseTalerUriAndRedirect(tabId, uri); +// } +// } /** * unused, declarative redirect is not good enough @@ -832,35 +838,36 @@ function registerTalerHeaderListener(): void { logger.info("setting up header listener"); const prevHeaderListener = currentHeaderListener; - const prevTabListener = currentTabListener; + // const prevTabListener = currentTabListener; if ( prevHeaderListener && chrome?.webRequest?.onHeadersReceived?.hasListener(prevHeaderListener) ) { - console.log("removming on header listener") - chrome.webRequest.onHeadersReceived.removeListener(prevHeaderListener); + return; + // console.log("removming on header listener") + // chrome.webRequest.onHeadersReceived.removeListener(prevHeaderListener); // chrome.webRequest.onCompleted.removeListener(prevHeaderListener); // chrome.webRequest.onResponseStarted.removeListener(prevHeaderListener); // chrome.webRequest.onErrorOccurred.removeListener(prevHeaderListener); } - if ( - prevTabListener && - chrome?.tabs?.onUpdated?.hasListener(prevTabListener) - ) { - console.log("removming on tab listener") - chrome.tabs.onUpdated.removeListener(prevTabListener); - } + + // if ( + // prevTabListener && + // chrome?.tabs?.onUpdated?.hasListener(prevTabListener) + // ) { + // console.log("removming on tab listener") + // chrome.tabs.onUpdated.removeListener(prevTabListener); + // } console.log("headers on, disabled:", chrome?.webRequest?.onHeadersReceived === undefined) if (chrome?.webRequest) { if (extensionIsManifestV3()) { chrome.webRequest.onHeadersReceived.addListener(headerListener, { urls: ["<all_urls>"] }, - ["responseHeaders", "extraHeaders"] + ["responseHeaders"] ); } else { - //Firefox doesnt support extra headers chrome.webRequest.onHeadersReceived.addListener(headerListener, { urls: ["<all_urls>"] }, ["responseHeaders"] @@ -881,12 +888,12 @@ function registerTalerHeaderListener(): void { currentHeaderListener = headerListener; } - const tabsEvent: chrome.tabs.TabUpdatedEvent | undefined = - chrome?.tabs?.onUpdated; - if (tabsEvent) { - tabsEvent.addListener(tabListener); - currentTabListener = tabListener; - } + // const tabsEvent: chrome.tabs.TabUpdatedEvent | undefined = + // chrome?.tabs?.onUpdated; + // if (tabsEvent) { + // tabsEvent.addListener(tabListener); + // currentTabListener = tabListener; + // } //notify the browser about this change, this operation is expensive chrome?.webRequest?.handlerBehaviorChanged(() => { @@ -933,15 +940,15 @@ export async function removeHostPermissions(): Promise<boolean> { ) { chrome.webRequest.onHeadersReceived.removeListener(currentHeaderListener); } - if ( - currentTabListener && - chrome?.tabs?.onUpdated?.hasListener(currentTabListener) - ) { - chrome.tabs.onUpdated.removeListener(currentTabListener); - } + // if ( + // currentTabListener && + // chrome?.tabs?.onUpdated?.hasListener(currentTabListener) + // ) { + // chrome.tabs.onUpdated.removeListener(currentTabListener); + // } currentHeaderListener = undefined; - currentTabListener = undefined; + // currentTabListener = undefined; //notify the browser about this change, this operation is expensive if ("webRequest" in chrome) { diff --git a/packages/taler-wallet-webextension/src/platform/firefox.ts b/packages/taler-wallet-webextension/src/platform/firefox.ts index cc734ebf7..0bbe805cf 100644 --- a/packages/taler-wallet-webextension/src/platform/firefox.ts +++ b/packages/taler-wallet-webextension/src/platform/firefox.ts @@ -48,7 +48,7 @@ function isFirefox(): boolean { } function addPermissionsListener(callback: (p: Permissions) => void): void { - throw Error("addPermissionListener is not supported for Firefox"); + // throw Error("addPermissionListener is not supported for Firefox"); } function getPermissionsApi(): CrossBrowserPermissionsApi { |