From 30303130751b5ae083bb6f73a9f86a3ce91156ee Mon Sep 17 00:00:00 2001 From: Spencer Murray Date: Mon, 28 Oct 2024 12:21:43 -0400 Subject: [PATCH] Make error handling better --- src/background/dynamic_content_scripts.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/background/dynamic_content_scripts.ts b/src/background/dynamic_content_scripts.ts index ae8c58d..3c926b8 100644 --- a/src/background/dynamic_content_scripts.ts +++ b/src/background/dynamic_content_scripts.ts @@ -41,8 +41,18 @@ export async function unregisterContentScriptIfExists( registrations = await browser.scripting.getRegisteredContentScripts({ ids: [dynamicContentScriptRegistrationId], }); - } catch (error) { - return true; + } catch (error: any) { + // Safari throws if the script id doesn't exist, so handle that gracefully + if ( + error instanceof Error && + error.message.match( + /Invalid call to scripting.getRegisteredContentScripts\(\)\. No script with ID '.*'/ + ) + ) { + return true; + } else { + throw error; + } } if (registrations.length === 0) {