Skip to content

Commit f1561a1

Browse files
authored
Reduce compute when unused (#72)
1 parent 271ab99 commit f1561a1

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

source/lib.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ function makePathRelative(file: string): string {
1717
async function registerOnOrigins({
1818
origins: newOrigins,
1919
}: chrome.permissions.Permissions): Promise<void> {
20+
if (!newOrigins?.length) {
21+
return;
22+
}
23+
2024
const {content_scripts: rawManifest, manifest_version: manifestVersion} = chrome.runtime.getManifest();
2125

2226
if (!rawManifest) {
@@ -26,7 +30,7 @@ async function registerOnOrigins({
2630
const cleanManifest = excludeDuplicateFiles(rawManifest, {warn: manifestVersion === 2});
2731

2832
// Register one at a time to allow removing one at a time as well
29-
for (const origin of newOrigins || []) {
33+
for (const origin of newOrigins) {
3034
for (const config of cleanManifest) {
3135
const registeredScript = registerContentScript({
3236
// Always convert paths here because we don't know whether Firefox MV3 will accept full URLs
@@ -43,17 +47,15 @@ async function registerOnOrigins({
4347

4448
// May not be needed in the future in Firefox
4549
// https://bugzilla.mozilla.org/show_bug.cgi?id=1458947
46-
void injectToExistingTabs(newOrigins || [], cleanManifest);
50+
void injectToExistingTabs(newOrigins, cleanManifest);
4751
}
4852

4953
function handleNewPermissions(permissions: chrome.permissions.Permissions) {
50-
if (permissions.origins && permissions.origins.length > 0) {
51-
void registerOnOrigins(permissions);
52-
}
54+
void registerOnOrigins(permissions);
5355
}
5456

5557
async function handledDroppedPermissions({origins}: chrome.permissions.Permissions) {
56-
if (!origins || origins.length === 0) {
58+
if (!origins?.length) {
5759
return;
5860
}
5961

0 commit comments

Comments
 (0)