Skip to content

Commit

Permalink
isPersistentBackgroundPage: Avoid false positive on MV3 Firefox (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante authored Feb 1, 2024
1 parent 148ef47 commit 75576b4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ export const isBackgroundWorker = once(
);

/** Indicates whether the code is being run in a persistent background page (as opposed to an Event Page or Background Worker, both of which can be unloaded by the browser) */
export const isPersistentBackgroundPage = (): boolean => isBackgroundPage() && getManifest(2)?.background?.persistent !== false;
export const isPersistentBackgroundPage = once((): boolean =>
isBackgroundPage()
&& getManifest(2)?.manifest_version === 2 // Firefox can have a background page on MV3, but can't be persistent
&& getManifest(2)?.background?.persistent !== false,
);

/** Indicates whether the code is being run in an options page. This only works if the current page’s URL matches the one specified in the extension's `manifest.json` */
export const isOptionsPage = once((): boolean => {
Expand Down

0 comments on commit 75576b4

Please sign in to comment.