From 429d1475ebfda21076c04970fad69402740bc541 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Mon, 24 Jun 2024 16:42:56 -0230 Subject: [PATCH] Update error handling to avoid crashing We now capture unrecognized errors and report them to Sentry, rather than throwing them. This ensures that any new failures would not brick the wallet. --- app/scripts/offscreen.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/app/scripts/offscreen.js b/app/scripts/offscreen.js index 556561c7dd46..cb18f393e11d 100644 --- a/app/scripts/offscreen.js +++ b/app/scripts/offscreen.js @@ -1,3 +1,4 @@ +import { captureException } from '@sentry/browser'; import { OffscreenCommunicationTarget } from '../../shared/constants/offscreen-communication'; /** @@ -37,20 +38,22 @@ export async function createOffscreen() { 'Used for Hardware Wallet and Snaps scripts to communicate with the extension.', }); } catch (error) { + if (offscreenDocumentLoadedListener) { + chrome.runtime.onMessage.removeListener(offscreenDocumentLoadedListener); + } if ( error?.message?.startsWith( 'Only a single offscreen document may be created', ) ) { console.debug('Offscreen document already exists; skipping creation'); - if (offscreenDocumentLoadedListener) { - chrome.runtime.onMessage.removeListener( - offscreenDocumentLoadedListener, - ); - } - return; + } else { + // Report unrecongized errors without halting wallet initialization + // Failures to create the offscreen document does not compromise wallet data integrity or + // core functionality, it's just needed for specific features. + captureException(error); } - throw error; + return; } // In case we are in a bad state where the offscreen document is not loading, timeout and let execution continue.