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 📖

fix(capture): hide start capture on pages that cannot be recorded

Luis Ortizad05244d9fdc
diff --git a/src/core/capture/__tests__/recordable-tabs.test.ts b/src/core/capture/__tests__/recordable-tabs.test.ts
new file mode 100644
index 0000000..76d82a1
--- /dev/null
+++ b/src/core/capture/__tests__/recordable-tabs.test.ts
@@ -0,0 +1,26 @@
+import { describe, expect, it } from 'vitest';
+import { isRecordableUrl } from '../recordable-tabs';
+
+describe('isRecordableUrl', () => {
+ it('accepts http and https pages', () => {
+ expect(isRecordableUrl('https://example.test/path')).toBe(true);
+ expect(isRecordableUrl('http://localhost:3000')).toBe(true);
+ });
+
+ it('rejects pages no content script can reach', () => {
+ for (const url of [
+ undefined,
+ '',
+ 'chrome://settings',
+ 'chrome-extension://abc/fullview.html',
+ 'about:blank',
+ 'file:///home/user/doc.pdf',
+ 'view-source:https://example.test',
+ 'edge://extensions',
+ 'https://chrome.google.com/webstore/category/extensions',
+ 'https://chromewebstore.google.com/detail/mimik/abc',
+ ]) {
+ expect(isRecordableUrl(url), url).toBe(false);
+ }
+ });
+});
diff --git a/src/core/capture/recordable-tabs.ts b/src/core/capture/recordable-tabs.ts
index 6a144b4..f0f909a 100644
--- a/src/core/capture/recordable-tabs.ts
+++ b/src/core/capture/recordable-tabs.ts
@@ -1,6 +1,6 @@
import { queryTabs } from '@/lib/browser-api';
-const WEBSTORE_PREFIX = 'https://chrome.google.com/webstore';
+const WEBSTORE_PREFIXES = ['https://chrome.google.com/webstore', 'https://chromewebstore.google.com'];
export interface RecordableTab {
id: number;
@@ -10,7 +10,7 @@ export interface RecordableTab {
}
export function isRecordableUrl(url: string | undefined): boolean {
- if (!url || url.startsWith(WEBSTORE_PREFIX)) return false;
+ if (!url || WEBSTORE_PREFIXES.some((prefix) => url.startsWith(prefix))) return false;
return /^https?:/.test(url);
}
diff --git a/src/locales/de.yml b/src/locales/de.yml
index 0a0af92..f1cbc1c 100644
--- a/src/locales/de.yml
+++ b/src/locales/de.yml
@@ -29,6 +29,7 @@ sidepanel:
startCapture: Aufnahme starten
searchPlaceholder: Anleitungen durchsuchen...
recentLabel: Zuletzt verwendet
+ notRecordable: Öffne eine Website, um aufzuzeichnen
library:
noGuidesTitle: Noch keine Anleitungen
diff --git a/src/locales/en.yml b/src/locales/en.yml
index bb735c7..4f6f441 100644
--- a/src/locales/en.yml
+++ b/src/locales/en.yml
@@ -29,6 +29,7 @@ sidepanel:
startCapture: Start Capture
searchPlaceholder: Search guides...
recentLabel: Recent
+ notRecordable: Open a website to start capturing
library:
noGuidesTitle: No guides yet
diff --git a/src/locales/es.yml b/src/locales/es.yml
index 5d27af2..4a2f661 100644
--- a/src/locales/es.yml
+++ b/src/locales/es.yml
@@ -29,6 +29,7 @@ sidepanel:
startCapture: Empezar a capturar
searchPlaceholder: Buscar guías...
recentLabel: Recientes
+ notRecordable: Abre un sitio web para empezar a grabar
library:
noGuidesTitle: No hay guías todavía
diff --git a/src/locales/fr.yml b/src/locales/fr.yml
index 4a752a9..5e1d3cc 100644
--- a/src/locales/fr.yml
+++ b/src/locales/fr.yml
@@ -29,6 +29,7 @@ sidepanel:
startCapture: Lancer la capture
searchPlaceholder: "Rechercher des guides..."
recentLabel: "Récents"
+ notRecordable: "Ouvrez un site web pour lancer la capture"
library:
noGuidesTitle: Pas encore de guide
diff --git a/src/locales/pt-BR.yml b/src/locales/pt-BR.yml
index 9561d5a..d8a2889 100644
--- a/src/locales/pt-BR.yml
+++ b/src/locales/pt-BR.yml
@@ -29,6 +29,7 @@ sidepanel:
startCapture: Começar a capturar
searchPlaceholder: Buscar guias...
recentLabel: Recentes
+ notRecordable: Abra um site para começar a gravar
library:
noGuidesTitle: Nenhum guia ainda
diff --git a/src/ui/sidepanel/App.tsx b/src/ui/sidepanel/App.tsx
index a3bfe7f..ec8e38c 100644
--- a/src/ui/sidepanel/App.tsx
+++ b/src/ui/sidepanel/App.tsx
@@ -1,7 +1,8 @@
-import { Search, Settings, Video } from 'lucide-react';
+import { Globe, Search, Settings, Video } from 'lucide-react';
import { useCallback, useEffect, useState } from 'react';
import { browser, i18n } from '#imports';
import { CaptureState } from '@/core/capture/machine';
+import { isRecordableUrl } from '@/core/capture/recordable-tabs';
import { startInsertRecording } from '@/core/capture/start-insert-recording';
import type { GuideMeSession } from '@/core/guideme/session';
import { SESSION_KEY } from '@/core/guideme/session';
@@ -91,6 +92,7 @@ export default function App() {
const [_isRecording, setIsRecording] = useState(false);
const [view, setView] = useState<View>({ name: 'library' });
const [search, setSearch] = useState('');
+ const [activeUrl, setActiveUrl] = useState<string>();
const [voice, setVoice] = useState<PanelVoiceUpdate>({ type: 'VOICE_UPDATE', phase: 'idle' });
const [voiceStarted, setVoiceStarted] = useState(false);
@@ -148,6 +150,17 @@ export default function App() {
return () => browser.storage.local.onChanged.removeListener(handler);
}, []);
+ useEffect(() => {
+ const refresh = () => getActiveTab().then((tab) => setActiveUrl(tab?.url || tab?.pendingUrl || ''));
+ refresh();
+ browser.tabs.onActivated.addListener(refresh);
+ browser.tabs.onUpdated.addListener(refresh);
+ return () => {
+ browser.tabs.onActivated.removeListener(refresh);
+ browser.tabs.onUpdated.removeListener(refresh);
+ };
+ }, []);
+
const handleStartRecording = useCallback(async () => {
const permissionsPromise = requestHostPermissions();
const granted = await permissionsPromise;
@@ -156,7 +169,11 @@ export default function App() {
return;
}
const tab = await getActiveTab();
- const url = tab?.url || '';
+ const url = tab?.url || tab?.pendingUrl || '';
+ if (!isRecordableUrl(url)) {
+ logger.warn('Active tab can no longer be recorded');
+ return;
+ }
try {
const res = await sendMessage('startRecording', { url });
@@ -276,14 +293,21 @@ export default function App() {
<p className="text-xs mt-1 text-violet-dark">{i18n.t('sidepanel.heroSubtitle')}</p>
</div>
- <Button
- onClick={handleStartRecording}
- disabled={!isAlive}
- className="w-full py-3 px-4 h-auto rounded-lg font-semibold text-sm hover:-translate-y-px shadow-lg"
- >
- <Video size={18} />
- {i18n.t('sidepanel.startCapture')}
- </Button>
+ {isRecordableUrl(activeUrl) ? (
+ <Button
+ onClick={handleStartRecording}
+ disabled={!isAlive}
+ className="w-full py-3 px-4 h-auto rounded-lg font-semibold text-sm hover:-translate-y-px shadow-lg"
+ >
+ <Video size={18} />
+ {i18n.t('sidepanel.startCapture')}
+ </Button>
+ ) : (
+ <p className="flex items-center justify-center gap-1.5 text-xs font-medium text-violet-dark">
+ <Globe size={14} className="shrink-0" />
+ {i18n.t('sidepanel.notRecordable')}
+ </p>
+ )}
</div>
{/* Body */}