Skip to content

Commit 3030313

Browse files
committed
Make error handling better
1 parent 8a4c236 commit 3030313

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/background/dynamic_content_scripts.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,18 @@ export async function unregisterContentScriptIfExists(
4141
registrations = await browser.scripting.getRegisteredContentScripts({
4242
ids: [dynamicContentScriptRegistrationId],
4343
});
44-
} catch (error) {
45-
return true;
44+
} catch (error: any) {
45+
// Safari throws if the script id doesn't exist, so handle that gracefully
46+
if (
47+
error instanceof Error &&
48+
error.message.match(
49+
/Invalid call to scripting.getRegisteredContentScripts\(\)\. No script with ID '.*'/
50+
)
51+
) {
52+
return true;
53+
} else {
54+
throw error;
55+
}
4656
}
4757

4858
if (registrations.length === 0) {

0 commit comments

Comments
 (0)