diff --git a/src/contrib/uipath/LocalProcessOptions.tsx b/src/contrib/uipath/LocalProcessOptions.tsx index b6c9da5036..5b6dd5d5db 100644 --- a/src/contrib/uipath/LocalProcessOptions.tsx +++ b/src/contrib/uipath/LocalProcessOptions.tsx @@ -42,7 +42,7 @@ const LocalProcessOptions: React.FunctionComponent = ({ }) => { // Crash the React tree, because it's a programming error to use this configuration outside the dev tools expectContext( - "devTools", + "pageEditor", "useLocalRobot only works in the Page Editor due to its `thisTab` usage", ); diff --git a/src/utils/expectContext.ts b/src/utils/expectContext.ts index fd5ee2fba6..a3471f5dd5 100644 --- a/src/utils/expectContext.ts +++ b/src/utils/expectContext.ts @@ -20,7 +20,6 @@ import { isContentScript, isExtensionContext, isWebPage, - contextNames, } from "webext-detect-page"; function isBrowserSidebar(): boolean { @@ -52,18 +51,15 @@ function createError( return new errorOrCtor(defaultMessage); } -// eslint-disable-next-line local-rules/persistBackgroundData -- Static -const contexts = [...contextNames, "sidebar", "pageEditor"] as const; - // eslint-disable-next-line local-rules/persistBackgroundData -- Functions -const contextMap = new Map<(typeof contexts)[number], () => boolean>([ - ["web", isWebPage], - ["extension", isExtensionContext], - ["background", isBackground], - ["pageEditor", isPageEditor], - ["contentScript", isContentScript], - ["sidebar", isBrowserSidebar], -]); +const contextMap = { + web: isWebPage, + extension: isExtensionContext, + background: isBackground, + pageEditor: isPageEditor, + contentScript: isContentScript, + sidebar: isBrowserSidebar, +} as const; /** * @example expectContext('extension') @@ -72,10 +68,10 @@ const contextMap = new Map<(typeof contexts)[number], () => boolean>([ * @example expectContext('extension', new Error('Wrong context and this is my custom error')) */ export function expectContext( - context: (typeof contexts)[number], + context: keyof typeof contextMap, error?: ErrorBaseType, ): void { - const isContext = contextMap.get(context); + const isContext = contextMap[context]; if (!isContext) { throw new TypeError(`Context "${context}" not found`); } @@ -95,10 +91,10 @@ export function expectContext( * @example forbidContext('extension', new Error('Wrong context and this is my custom error')) */ export function forbidContext( - context: (typeof contexts)[number], + context: keyof typeof contextMap, error?: ErrorBaseType, ): void { - const isContext = contextMap.get(context); + const isContext = contextMap[context]; if (!isContext) { throw new TypeError(`Context "${context}" not found`); }