Skip to content

Commit

Permalink
Make error handling better
Browse files Browse the repository at this point in the history
  • Loading branch information
spalmurray-codecov committed Oct 28, 2024
1 parent 8a4c236 commit 3030313
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/background/dynamic_content_scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 3030313

Please sign in to comment.