Skip to content

Commit

Permalink
add additional optional chaining to prevent import errors where the c…
Browse files Browse the repository at this point in the history
…hrome api is not available
  • Loading branch information
mnholtz committed May 9, 2024
1 parent 908151e commit 120583e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions src/mv3/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
import { type Tabs } from "webextension-polyfill";
import { once } from "lodash";

export const isMV3 = once(
(): boolean =>
// Use optional chaining in case the chrome runtime is not available:
// https://github.com/pixiebrix/pixiebrix-extension/issues/8273
chrome.runtime?.getManifest().manifest_version === 3,
);
export const isMV3 = once((): boolean => {
if (!chrome.runtime?.getManifest) {
return false;
}

// Use optional chaining in case the chrome runtime is not available:
// https://github.com/pixiebrix/pixiebrix-extension/issues/8273
return chrome.runtime.getManifest().manifest_version === 3;
});
export const browserAction =
globalThis.chrome?.browserAction ?? globalThis.chrome?.action;
export type Tab = Tabs.Tab | chrome.tabs.Tab;
2 changes: 1 addition & 1 deletion src/tinyPages/offscreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let createOffscreenDocumentPromise: Promise<void> | null = null;

// Use optional chaining in case the chrome runtime is not available:
// https://github.com/pixiebrix/pixiebrix-extension/issues/8397
chrome.runtime?.onMessage.addListener(handleMessages);
chrome.runtime?.onMessage?.addListener(handleMessages);

export type RecordErrorMessage = {
target: "offscreen-doc";
Expand Down

0 comments on commit 120583e

Please sign in to comment.