Skip to content

armgit / mimik

Public Imported from GitHub
0

🎬 A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots πŸ“–

feat: add Firefox as a build target

Luis Ortiz9a576a7953c0
diff --git a/README.md b/README.md
index 30e8c09..1336ddf 100644
--- a/README.md
+++ b/README.md
@@ -64,6 +64,19 @@ npx wxt build
# 4. Select the .output/chrome-mv3 folder
```
+### Firefox
+
+Mimik builds for Firefox from the same codebase.
+
+```bash
+pnpm dev:firefox # development
+pnpm build:firefox # production build
+pnpm zip:firefox # package for addons.mozilla.org
+pnpm zip:all # both Chrome and Firefox
+```
+
+Firefox build output lands in `.output/firefox-mv3/`.
+
## Project Structure
```
diff --git a/package.json b/package.json
index f6c52eb..2557f86 100644
--- a/package.json
+++ b/package.json
@@ -5,8 +5,12 @@
"main": "index.js",
"scripts": {
"dev": "wxt",
+ "dev:firefox": "wxt -b firefox --mv3",
"build": "wxt build",
+ "build:firefox": "wxt build -b firefox --mv3",
"zip": "wxt zip",
+ "zip:firefox": "wxt zip -b firefox --mv3",
+ "zip:all": "pnpm zip && pnpm zip:firefox",
"test": "vitest run",
"test:watch": "vitest",
"test:cov": "vitest run --coverage",
diff --git a/src/entrypoints/background/index.ts b/src/entrypoints/background/index.ts
index 7fdcacd..8ddf4b5 100644
--- a/src/entrypoints/background/index.ts
+++ b/src/entrypoints/background/index.ts
@@ -61,6 +61,11 @@ export default defineBackground(() => {
});
setSidePanelBehavior(true);
+ if (import.meta.env.BROWSER === 'firefox') {
+ browser.action.onClicked.addListener(() => {
+ browser.sidebarAction.toggle();
+ });
+ }
initActor().catch(initActorFallback);
cancelSession();
registerNavigationListeners();
diff --git a/src/lib/browser-api.ts b/src/lib/browser-api.ts
index 2ad7897..80654c9 100644
--- a/src/lib/browser-api.ts
+++ b/src/lib/browser-api.ts
@@ -109,11 +109,44 @@ export const localStorage = {
};
export function setSidePanelBehavior(openOnActionClick: boolean): void {
+ if (import.meta.env.BROWSER === 'firefox') return;
browser.sidePanel.setPanelBehavior({
openPanelOnActionClick: openOnActionClick,
});
}
+export function openSidebar(): void {
+ if (import.meta.env.BROWSER === 'firefox') {
+ browser.sidebarAction.open();
+ } else {
+ browser.sidePanel.open({ windowId: chrome.windows.WINDOW_ID_CURRENT });
+ }
+}
+
+export function toggleSidebar(): void {
+ if (import.meta.env.BROWSER === 'firefox') {
+ browser.sidebarAction.toggle();
+ }
+}
+
+export function requestHostPermissions(): Promise<boolean> {
+ if (import.meta.env.BROWSER !== 'firefox') return Promise.resolve(true);
+ try {
+ return browser.permissions.request({ origins: ['<all_urls>'] }).catch(() => false);
+ } catch {
+ return Promise.resolve(false);
+ }
+}
+
+export async function hasHostPermissions(): Promise<boolean> {
+ if (import.meta.env.BROWSER !== 'firefox') return true;
+ try {
+ return await browser.permissions.contains({ origins: ['<all_urls>'] });
+ } catch {
+ return false;
+ }
+}
+
export function onNavigationCompleted(
handler: (details: Browser.webNavigation.WebNavigationFramedCallbackDetails) => void,
): void {
diff --git a/src/ui/fullview/GuideContent.tsx b/src/ui/fullview/GuideContent.tsx
index 414df02..f0b9072 100644
--- a/src/ui/fullview/GuideContent.tsx
+++ b/src/ui/fullview/GuideContent.tsx
@@ -11,6 +11,7 @@ import {
updateStepDescription,
} from '@/core/guides/service';
import type { Guide, Screenshot, Step } from '@/core/guides/types';
+import { openSidebar } from '@/lib/browser-api';
import { sendMessage } from '@/lib/messaging';
import { formatDate, getMostCommonDomain } from '@/lib/utils';
import { useFullview } from '@/stores/fullview';
@@ -213,9 +214,9 @@ export default function GuideContent({ guideId }: GuideContentProps) {
)}
{data.steps.length > 0 && (
<button
- onClick={async () => {
- await chrome.sidePanel.open({ windowId: chrome.windows.WINDOW_ID_CURRENT });
- await sendMessage('startGuideMe', { guideId });
+ onClick={() => {
+ openSidebar();
+ void sendMessage('startGuideMe', { guideId });
}}
disabled={!data.steps.some((s) => s.elementMeta)}
className="inline-flex items-center gap-1.5 text-[11px] font-semibold text-primary-foreground bg-primary hover:bg-primary/90 px-3 py-0.5 rounded-full transition-colors disabled:opacity-30 disabled:cursor-not-allowed ml-auto"
diff --git a/src/ui/onboarding/App.tsx b/src/ui/onboarding/App.tsx
index 1bfbfd7..c250672 100644
--- a/src/ui/onboarding/App.tsx
+++ b/src/ui/onboarding/App.tsx
@@ -3,7 +3,7 @@ import { browser, i18n } from '#imports';
import { PRESET_LABELS, type PresetKey } from '@/core/blur/regexes';
import { AI_PROVIDERS, type AIProviderKey } from '@/core/capture/ai/models';
import { AI_LANGUAGES, type AILanguageCode } from '@/core/capture/ai/prompts';
-import { localStorage } from '@/lib/browser-api';
+import { localStorage, requestHostPermissions } from '@/lib/browser-api';
const BLUR_PRESET_I18N: Record<PresetKey, string> = {
email: 'email',
@@ -489,7 +489,9 @@ function PinExtensionStep({ onNext, onSkip }: { onNext: () => void; onSkip: () =
}
function DoneStep() {
- const handleOpen = () => {
+ const handleOpen = async () => {
+ const permissionsPromise = requestHostPermissions();
+ await permissionsPromise;
browser.tabs.create({ url: browser.runtime.getURL('/fullview.html') });
};
diff --git a/src/ui/sidepanel/App.tsx b/src/ui/sidepanel/App.tsx
index 289e8b8..c574f0f 100644
--- a/src/ui/sidepanel/App.tsx
+++ b/src/ui/sidepanel/App.tsx
@@ -4,7 +4,15 @@ import { browser, i18n } from '#imports';
import { CaptureState } from '@/core/capture/machine';
import type { GuideMeSession } from '@/core/guideme/session';
import { SESSION_KEY } from '@/core/guideme/session';
-import { createTab, focusWindow, getActiveTab, getExtensionURL, queryTabs, updateTab } from '@/lib/browser-api';
+import {
+ createTab,
+ focusWindow,
+ getActiveTab,
+ getExtensionURL,
+ queryTabs,
+ requestHostPermissions,
+ updateTab,
+} from '@/lib/browser-api';
import { logger } from '@/lib/logger';
import { sendMessage } from '@/lib/messaging';
import { connectToBackground } from '@/lib/port';
@@ -117,6 +125,12 @@ export default function App() {
}, []);
const handleStartRecording = useCallback(async () => {
+ const permissionsPromise = requestHostPermissions();
+ const granted = await permissionsPromise;
+ if (!granted) {
+ logger.warn('Host permissions not granted, cannot start recording');
+ return;
+ }
const tab = await getActiveTab();
const url = tab?.url || '';
diff --git a/wxt.config.ts b/wxt.config.ts
index ccb1018..28eb463 100644
--- a/wxt.config.ts
+++ b/wxt.config.ts
@@ -14,30 +14,58 @@ export default defineConfig({
vite: () => ({
plugins: [tailwindcss()],
}),
- manifest: {
- name: "__MSG_app_name__",
- description: "__MSG_app_description__",
- default_locale: "en",
- permissions: [
- "storage",
- "activeTab",
- "tabs",
- "scripting",
- "unlimitedStorage",
- "sidePanel",
- "webNavigation",
- ],
- host_permissions: ["<all_urls>"],
- minimum_chrome_version: "118",
- icons: {
- 16: 'icon16.png',
- 32: 'icon32.png',
- 48: 'icon48.png',
- 128: 'icon128.png',
- },
- action: {},
- side_panel: {
- default_path: "sidepanel/index.html",
+ hooks: {
+ 'build:manifestGenerated': (wxt, manifest) => {
+ if (wxt.config.browser === 'firefox' && manifest.sidebar_action) {
+ (manifest.sidebar_action as Record<string, unknown>).open_at_install = false;
+ (manifest.sidebar_action as Record<string, unknown>).default_icon = 'icon32.png';
+ }
},
},
+ manifest: ({ browser }) => {
+ const isFirefox = browser === 'firefox';
+ return {
+ name: "__MSG_app_name__",
+ description: "__MSG_app_description__",
+ default_locale: "en",
+ permissions: [
+ "storage",
+ "activeTab",
+ "tabs",
+ "scripting",
+ "unlimitedStorage",
+ "webNavigation",
+ ...(isFirefox ? [] : ["sidePanel"]),
+ ],
+ host_permissions: ["<all_urls>"],
+ ...(isFirefox ? {} : { minimum_chrome_version: "118" }),
+ icons: {
+ 16: 'icon16.png',
+ 32: 'icon32.png',
+ 48: 'icon48.png',
+ 128: 'icon128.png',
+ },
+ action: {},
+ ...(isFirefox
+ ? {
+ sidebar_action: {
+ default_panel: "sidepanel.html",
+ default_icon: "icon32.png",
+ default_title: "Mimik",
+ open_at_install: false,
+ },
+ browser_specific_settings: {
+ gecko: {
+ strict_min_version: "112.0",
+ },
+ },
+ }
+ : {
+ side_panel: {
+ default_path: "sidepanel/index.html",
+ },
+ }),
+ };
+ },
});