Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop vestigial Firefox support #7237

Merged
merged 8 commits into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pixiebrix-extension.iml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<content url="file://$MODULE_DIR$">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this file? It has some ancient directories

Copy link
Contributor

@twschiller twschiller Dec 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's from IntelliJ - those excludeFolder entries tell IntelliJ not to index those folders. The outdated directories don't hurt anything, but could drop them to clean up the file

<excludeFolder url="file://$MODULE_DIR$/artifacts" />
<excludeFolder url="file://$MODULE_DIR$/browsers/chrome/bundles" />
<excludeFolder url="file://$MODULE_DIR$/browsers/firefox/bundles" />
<excludeFolder url="file://$MODULE_DIR$/scripts/bin" />
<excludeFolder url="file://$MODULE_DIR$/dist" />
<excludeFolder url="file://$MODULE_DIR$/browsers/dist" />
Expand Down
9 changes: 0 additions & 9 deletions src/__mocks__/@/background/messenger/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,6 @@ import { RegistryId } from "@/types/registryTypes";
// Bypass auto-mocks
export * from "../../../../background/messenger/api";

// Chrome offers this API in more contexts than Firefox, so it skips the messenger entirely
export const containsPermissions = jest
.fn()
.mockRejectedValue(
new Error(
"Internal mocking error: jest should be using containsPermissions from mockPermissions",
),
);

export const getUID = jest.fn().mockResolvedValue(uuidv4());

export const pong = jest.fn(() => ({
Expand Down
2 changes: 0 additions & 2 deletions src/background/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import initNavigation from "@/background/navigation";
import initExecutor from "@/background/executor";
import initBrowserCommands from "@/background/initBrowserCommands";
import initDeploymentUpdater from "@/background/deploymentUpdater";
import initFirefoxCompat from "@/background/firefoxCompat";
import activateBrowserActionIcon from "@/background/activateBrowserActionIcon";
import initPartnerTheme from "@/background/partnerTheme";
import initStarterMods from "@/background/starterMods";
Expand All @@ -61,7 +60,6 @@ initContextMenus();
initContentScriptReadyListener();
initBrowserCommands();
initDeploymentUpdater();
initFirefoxCompat();
activateBrowserActionIcon();
initPartnerTheme();
initStarterMods();
Expand Down
33 changes: 0 additions & 33 deletions src/background/eventUtils.ts

This file was deleted.

42 changes: 0 additions & 42 deletions src/background/firefoxCompat.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/background/messenger/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,8 @@ import type { AxiosRequestConfig } from "axios";
import type { RemoteResponse } from "@/types/contract";
import { type SanitizedIntegrationConfig } from "@/integrations/integrationTypes";

// Chrome offers this API in more contexts than Firefox, so it skips the messenger entirely
export const containsPermissions = browser.permissions
? browser.permissions.contains
: getMethod("CONTAINS_PERMISSIONS", bg);

export const getAvailableVersion = getMethod("GET_AVAILABLE_VERSION", bg);
export const ensureContentScript = getMethod("INJECT_SCRIPT", bg);
export const openPopupPrompt = getMethod("OPEN_POPUP_PROMPT", bg);
export const getUID = getMethod("GET_UID", bg);
export const waitForTargetByUrl = getMethod("WAIT_FOR_TARGET_BY_URL", bg);

Expand Down
16 changes: 0 additions & 16 deletions src/background/messenger/external/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,6 @@ import { _liftBackground as liftExternal } from "@/background/externalProtocol";
import * as local from "@/background/messenger/external/_implementation";
import { readPartnerAuthData } from "@/auth/token";

// Disabled for now because we don't support Firefox
// import { liftExternalToContentScript } from "@/contentScript/externalProtocol";
// import { isChrome } from "webext-detect-page";
// import { type SerializableResponse } from "@/types/messengerTypes";
// const liftExternal = isChrome()
// ? // Chrome can communicate directly via the standard chrome.runtime.sendMessage API.
// _liftBackground
// : // Firefox doesn't support web-to-background communication, so it must be travel via the content script.
// <TArguments extends unknown[], R extends SerializableResponse>(
// type: string,
// method: (...args: TArguments) => Promise<R>,
// ) => {
// const liftedToBackground = _liftBackground(`BACKGROUND_${type}`, method);
// return liftExternalToContentScript(type, liftedToBackground);
// };

export const connectPage = liftExternal("CONNECT_PAGE", async () =>
browser.runtime.getManifest(),
);
Expand Down
5 changes: 0 additions & 5 deletions src/background/messenger/registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
preloadContextMenus,
uninstallContextMenu,
} from "@/background/contextMenus";
import { openPopupPrompt } from "@/background/permissionPrompt";
import {
activateTab,
closeTab,
Expand Down Expand Up @@ -99,11 +98,9 @@ declare global {

GET_AVAILABLE_VERSION: typeof getAvailableVersion;
INJECT_SCRIPT: typeof ensureContentScript;
CONTAINS_PERMISSIONS: typeof browser.permissions.contains;
PRELOAD_CONTEXT_MENUS: typeof preloadContextMenus;
UNINSTALL_CONTEXT_MENU: typeof uninstallContextMenu;
ENSURE_CONTEXT_MENU: typeof ensureContextMenu;
OPEN_POPUP_PROMPT: typeof openPopupPrompt;

ACTIVATE_PARTNER_THEME: typeof initPartnerTheme;
GET_PARTNER_PRINCIPALS: typeof getPartnerPrincipals;
Expand Down Expand Up @@ -189,12 +186,10 @@ export default function registerMessenger(): void {

GET_AVAILABLE_VERSION: getAvailableVersion,
INJECT_SCRIPT: ensureContentScript,
CONTAINS_PERMISSIONS: browser.permissions.contains,

PRELOAD_CONTEXT_MENUS: preloadContextMenus,
UNINSTALL_CONTEXT_MENU: uninstallContextMenu,
ENSURE_CONTEXT_MENU: ensureContextMenu,
OPEN_POPUP_PROMPT: openPopupPrompt,

GET_UID: uid,
WAIT_FOR_TARGET_BY_URL: waitForTargetByUrl,
Expand Down
76 changes: 0 additions & 76 deletions src/background/permissionPrompt.ts

This file was deleted.

16 changes: 3 additions & 13 deletions src/background/webextAlert.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
isBackgroundPage,
isBackgroundWorker,
isFirefox,
} from "webext-detect-page";
import { isBackgroundWorker } from "webext-detect-page";

function windowAlert(message: string): void {
const url = new URL(browser.runtime.getURL("alert.html"));
Expand All @@ -23,14 +19,8 @@ function windowAlert(message: string): void {
});
}

// No alert() in background workers
// eslint-disable-next-line local-rules/persistBackgroundData -- Function
const webextAlert = ((): typeof alert => {
if ((isFirefox() && isBackgroundPage()) || isBackgroundWorker()) {
// Firefox and workers don't support alert() in background pages
return windowAlert;
}

return alert;
})();
const webextAlert = isBackgroundWorker() ? windowAlert : alert;

export default webextAlert;
3 changes: 1 addition & 2 deletions src/components/errors/NetworkErrorDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
} from "@/errors/networkErrorHelpers";
import styles from "./ErrorDetail.module.scss";
import useAsyncState from "@/hooks/useAsyncState";
import { containsPermissions } from "@/background/messenger/api";
import AsyncStateGate from "@/components/AsyncStateGate";

function tryParse(value: unknown): unknown {
Expand All @@ -51,7 +50,7 @@ const NetworkErrorDetail: React.FunctionComponent<{
const absoluteUrl = selectAbsoluteUrl(error.config);

const permissionsState = useAsyncState<boolean | undefined>(
async () => containsPermissions({ origins: [absoluteUrl] }),
async () => browser.permissions.contains({ origins: [absoluteUrl] }),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Chrome there's no change, it was already short-circuited this way.

[absoluteUrl],
);

Expand Down
7 changes: 2 additions & 5 deletions src/contrib/zapier/PushOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ import { type Webhook } from "@/contrib/zapier/contract";
import { pixiebrixConfigurationFactory } from "@/integrations/locator";
import { getBaseURL } from "@/services/baseService";
import { ZAPIER_PERMISSIONS, ZAPIER_PROPERTIES } from "@/contrib/zapier/push";
import {
containsPermissions,
performConfiguredRequestInBackground,
} from "@/background/messenger/api";
import { performConfiguredRequestInBackground } from "@/background/messenger/api";
import AsyncButton from "@/components/AsyncButton";
import ConnectedFieldTemplate from "@/components/form/ConnectedFieldTemplate";
import SelectWidget from "@/components/form/widgets/SelectWidget";
Expand Down Expand Up @@ -101,7 +98,7 @@ const PushOptions: React.FunctionComponent<BlockOptionProps> = ({
const permissionsState = useExtensionPermissions();

const [hasPermissions] = useAsyncState(
async () => containsPermissions(ZAPIER_PERMISSIONS),
async () => browser.permissions.contains(ZAPIER_PERMISSIONS),
[permissionsState],
);

Expand Down
3 changes: 1 addition & 2 deletions src/modDefinitions/modDefinitionPermissionsHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
ensurePermissionsFromUserGesture,
mergePermissions,
} from "@/permissions/permissionsUtils";
import { containsPermissions } from "@/background/messenger/api";
import { isEmpty } from "lodash";
import { type Permissions } from "webextension-polyfill";
import extensionPointRegistry from "@/starterBricks/registry";
Expand Down Expand Up @@ -107,7 +106,7 @@ export async function checkModDefinitionPermissions(
}

return {
hasPermissions: await containsPermissions(permissions),
hasPermissions: await browser.permissions.contains(permissions),
permissions,
};
}
Expand Down
3 changes: 1 addition & 2 deletions src/pageEditor/editorPermissionsHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
import notify from "@/utils/notify";
import { type Permissions } from "webextension-polyfill";
import { castArray } from "lodash";
import { containsPermissions } from "@/background/messenger/api";

export async function calculatePermissionsForElement(
element: ModComponentFormState,
Expand All @@ -46,7 +45,7 @@ export async function calculatePermissionsForElement(
extensionPoint: starterBrick,
});

const hasPermissions = await containsPermissions(permissions);
const hasPermissions = await browser.permissions.contains(permissions);

return { hasPermissions, permissions };
}
Expand Down
3 changes: 1 addition & 2 deletions src/permissions/extensionPermissionsHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { castArray, compact } from "lodash";
import { mergePermissions } from "@/permissions/permissionsUtils";
import { type StarterBrick } from "@/types/starterBrickTypes";
import { collectIntegrationOriginPermissions } from "@/integrations/util/permissionsHelpers";
import { containsPermissions } from "@/background/messenger/api";
import { type PermissionsStatus } from "@/permissions/permissionsTypes";

type PermissionOptions = {
Expand Down Expand Up @@ -107,6 +106,6 @@ export async function checkExtensionPermissions(

return {
permissions,
hasPermissions: await containsPermissions(permissions),
hasPermissions: await browser.permissions.contains(permissions),
};
}
Loading
Loading