diff options
Diffstat (limited to 'packages/taler-wallet-webextension/src/platform')
-rw-r--r-- | packages/taler-wallet-webextension/src/platform/chrome.ts | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/packages/taler-wallet-webextension/src/platform/chrome.ts b/packages/taler-wallet-webextension/src/platform/chrome.ts index aac3b546c..7785e19ef 100644 --- a/packages/taler-wallet-webextension/src/platform/chrome.ts +++ b/packages/taler-wallet-webextension/src/platform/chrome.ts @@ -311,14 +311,17 @@ async function sendMessageToWalletBackground( chrome.runtime.sendMessage( { operation, payload, id: `id_${i++ % 1000}` }, (backgroundResponse) => { - logger.trace("BUG: got response from background", backgroundResponse); + logger.trace( + "BUG: got response from background", + backgroundResponse, + chrome.runtime.lastError, + ); if (chrome.runtime.lastError) { reject(chrome.runtime.lastError.message); + } else { + resolve(backgroundResponse); } - // const apiResponse = JSON.parse(resp) - resolve(backgroundResponse); - // return true to keep the channel open return true; }, @@ -355,13 +358,21 @@ function sendMessageToAllChannels(message: MessageFromBackend): void { function registerAllIncomingConnections(): void { chrome.runtime.onConnect.addListener((port) => { - allPorts.push(port); - port.onDisconnect.addListener((discoPort) => { - const idx = allPorts.indexOf(discoPort); - if (idx >= 0) { - allPorts.splice(idx, 1); - } - }); + try { + allPorts.push(port); + port.onDisconnect.addListener((discoPort) => { + try { + const idx = allPorts.indexOf(discoPort); + if (idx >= 0) { + allPorts.splice(idx, 1); + } + } catch (e) { + logger.error("error trying to remove connection", e); + } + }); + } catch (e) { + logger.error("error trying to save incoming connection", e); + } }); } @@ -375,7 +386,11 @@ function listenToAllChannels( chrome.runtime.onMessage.addListener((m, s, c) => { cb(m, s, (apiResponse) => { logger.trace("BUG: sending response to client", apiResponse); - c(apiResponse); + try { + c(apiResponse); + } catch (e) { + logger.error("wallet operation ended with error", e); + } }); // keep the connection open |