🎬 A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots 📖
TypeScript browser-extensionchrome-extensiondocumentationfirefox-extensionguide-generatorlocal-firstmanifest-v3privacy-firstproductivityreactscreenshotstep-by-step-guidetutorialtypescriptworkflowwxt
fix(capture): pause the state machine in blur mode
davbioebcb28c79c64
diff --git a/src/core/blur/manager.ts b/src/core/blur/manager.tsindex ec6ce13..4864c0a 100644--- a/src/core/blur/manager.ts+++ b/src/core/blur/manager.ts@@ -22,29 +22,57 @@ export class BlurManager {private picker = new ElementPicker();private panel: BlurPanel | null = null;private active = false;+ private generation = 0;async start() {if (this.active) return;this.active = true;+ // A stop or dismiss can land while the presets load, and so can a second+ // start() after one. `active` alone cannot tell "still the same start" from+ // "stopped and started again", and a stale continuation that mounts a panel+ // drops the reference to the live one, leaving it in the DOM unclosable.+ const generation = ++this.generation;+injectBlurStyles();const presets = await this.loadPresets();+ if (!this.active || generation !== this.generation) return;+const activeKeys = (Object.entries(presets) as [PresetKey, boolean][]).filter(([, on]) => on).map(([k]) => k);this.scanner.start(activeKeys);+ this.panel?.unmount();this.panel = new BlurPanel(presets);this.panel.mount();for (const event of EVENTS) document.addEventListener(event, this.handleEvent);}+ /**+ * Closes the overlay and removes every mask. For the end of a recording.+ *+ * Only the teardown is conditional on `active`: "Done" already tore the panel+ * down and left the masks in place, so gating the whole method would make this+ * a no-op on the one path that matters — the page would keep its injected+ * style, its mask spans and its blurred inputs until the user reloaded, and+ * the surviving attributes would keep withholding input values from the next+ * recording. Both calls below are idempotent on a page that never blurred.+ */stop() {- if (!this.active) return;- this.teardown();+ if (this.active) this.teardown();this.scanner.stop();removeBlurStyles();}+ /**+ * Closes the overlay but leaves the masks in place, which is what "Done"+ * does: the point of picking them is that later screenshots keep them.+ */+ dismiss() {+ if (!this.active) return;+ this.teardown();+ }+private teardown() {this.active = false;this.panel?.unmount();diff --git a/src/core/blur/restore.ts b/src/core/blur/restore.tsnew file mode 100644index 0000000..7737c68--- /dev/null+++ b/src/core/blur/restore.ts@@ -0,0 +1,15 @@+import { CaptureState } from '@/core/capture/machine';+import type { GetStateResponse } from '@/lib/messaging';++/**+ * Whether a frame booting mid-recording should re-open the blur overlay.+ *+ * Only the top frame ever hosts it, and only while the recording is paused+ * *for blur* — a manual pause has no overlay to restore, and a live recording+ * must not have one dropped on top of it. Without this the page that loads+ * after a navigation mid-blur would have no Done button, leaving the user+ * paused with no way back from the page itself.+ */+export function shouldReopenBlur(state: GetStateResponse, isTopFrame: boolean): boolean {+ return isTopFrame && state.state === CaptureState.PAUSED && state.pauseReason === 'blur';+}diff --git a/src/core/capture/events/handlers.ts b/src/core/capture/events/handlers.tsindex c7bf2a9..a9c1f0c 100644--- a/src/core/capture/events/handlers.ts+++ b/src/core/capture/events/handlers.ts@@ -50,7 +50,9 @@ let lastClickTarget: Element | null = null;let lastClickTime = 0;export interface CaptureHandle {- stop: () => void;+ /** Resolves once queued work has drained, so a caller can wait for the+ * final input screenshot to land before pausing. */+ stop: () => Promise<void>;}const PASSIVE_CAPTURE = { capture: true, passive: true } as const;@@ -313,13 +315,14 @@ class CaptureController {this.enqueue(this.capture('drag', findFocusableAncestor(target)));}- stop() {+ stop(): Promise<void> {for (const [event, handler, opts] of this.listeners) {window.removeEventListener(event, handler, opts);}this.hovered = null;this.ring.dispose();this.queue.add(() => this.input.finalize());+ return this.queue.onIdle();}}diff --git a/src/core/capture/machine.ts b/src/core/capture/machine.tsindex d144355..1521c2a 100644--- a/src/core/capture/machine.ts+++ b/src/core/capture/machine.ts@@ -3,13 +3,19 @@ import { assign, createMachine, type SnapshotFrom } from 'xstate';export const CaptureState = {IDLE: 'IDLE',RECORDING: 'RECORDING',+ PAUSED: 'PAUSED',} as const;export type CaptureStateValue = (typeof CaptureState)[keyof typeof CaptureState];+/** Why capture is paused: the blur overlay is open, or the user pressed pause. */+export type PauseReason = 'blur' | 'manual';+type CaptureEvent =| { type: 'START_RECORDING'; url?: string; insertTargetGuideId?: string; insertAtIndex?: number }| { type: 'STOP_RECORDING' }+ | { type: 'PAUSE_CAPTURE'; reason: PauseReason }+ | { type: 'RESUME_CAPTURE' }| { type: 'USER_ACTION' }| { type: 'URL_CHANGED'; url: string };@@ -19,8 +25,18 @@ interface CaptureContext {currentUrl: string;insertTargetGuideId: string | null;insertAtIndex: number | null;+ pauseReason: PauseReason | null;}+const IDLE_CONTEXT: CaptureContext = {+ currentGuideId: null,+ stepCount: 0,+ currentUrl: '',+ insertTargetGuideId: null,+ insertAtIndex: null,+ pauseReason: null,+};+export const captureMachine = createMachine({id: 'capture',initial: CaptureState.IDLE,@@ -28,13 +44,7 @@ export const captureMachine = createMachine({context: CaptureContext;events: CaptureEvent;},- context: {- currentGuideId: null,- stepCount: 0,- currentUrl: '',- insertTargetGuideId: null,- insertAtIndex: null,- },+ context: { ...IDLE_CONTEXT },states: {[CaptureState.IDLE]: {on: {@@ -46,6 +56,7 @@ export const captureMachine = createMachine({currentUrl: ({ event }) => event.url ?? '',insertTargetGuideId: ({ event }) => event.insertTargetGuideId ?? null,insertAtIndex: ({ event }) => event.insertAtIndex ?? null,+ pauseReason: null,}),},},@@ -54,12 +65,12 @@ export const captureMachine = createMachine({on: {STOP_RECORDING: {target: CaptureState.IDLE,+ actions: assign({ ...IDLE_CONTEXT }),+ },+ PAUSE_CAPTURE: {+ target: CaptureState.PAUSED,actions: assign({- currentGuideId: null,- stepCount: 0,- currentUrl: '',- insertTargetGuideId: null,- insertAtIndex: null,+ pauseReason: ({ event }) => event.reason,}),},USER_ACTION: {@@ -74,6 +85,26 @@ export const captureMachine = createMachine({},},},+ // No USER_ACTION here on purpose: while paused, nothing can advance the+ // step count, so the "capture paused" label cannot be contradicted by a+ // frame that missed the stop broadcast.+ [CaptureState.PAUSED]: {+ on: {+ RESUME_CAPTURE: {+ target: CaptureState.RECORDING,+ actions: assign({ pauseReason: null }),+ },+ STOP_RECORDING: {+ target: CaptureState.IDLE,+ actions: assign({ ...IDLE_CONTEXT }),+ },+ URL_CHANGED: {+ actions: assign({+ currentUrl: ({ event }) => event.url,+ }),+ },+ },+ },},});diff --git a/src/core/capture/session.ts b/src/core/capture/session.tsindex d2f0c7b..ae5b481 100644--- a/src/core/capture/session.ts+++ b/src/core/capture/session.ts@@ -1,5 +1,5 @@import { logger } from '@/lib/logger';-import { sendMessage } from '@/lib/messaging';+import { type GetStateResponse, sendMessage } from '@/lib/messaging';import { type CaptureHandle, startCapture } from './events/handlers';import { CaptureState } from './machine';@@ -8,7 +8,12 @@ export class CaptureSession {private activeGuideId: string | null = null;private disabled = false;- constructor() {+ /**+ * @param onSynced Called once with whatever the background reports when this+ * frame boots, so a caller can react to states this session ignores —+ * notably PAUSED, which must re-open the blur overlay rather than capture.+ */+ constructor(private readonly onSynced?: (state: GetStateResponse) => void) {this.syncWithBackground();}@@ -36,13 +41,16 @@ export class CaptureSession {this.capture = startCapture(guideId, isTopFrame);}- stop(): void {- if (!this.isActive) return;+ /** Resolves once in-flight capture work has drained. Callers that pause a+ * recording await this so a typing session's final screenshot still lands. */+ stop(): Promise<void> {+ if (!this.isActive) return Promise.resolve();logger.info('Capture stopped → guideId:', this.activeGuideId);- this.capture?.stop();+ const draining = this.capture?.stop() ?? Promise.resolve();this.capture = null;this.activeGuideId = null;+ return draining;}private syncWithBackground(): void {@@ -52,6 +60,7 @@ export class CaptureSession {if (res.state === CaptureState.RECORDING && res.currentGuideId) {this.start(res.currentGuideId);}+ this.onSynced?.(res);}).catch(() => {});}diff --git a/src/core/guides/types.ts b/src/core/guides/types.tsindex 3a34bb2..73aba6b 100644--- a/src/core/guides/types.ts+++ b/src/core/guides/types.ts@@ -84,7 +84,6 @@ export interface Settings {guideMeStep: Step | null;guideMeBlocked: number | null;guideMeManual: boolean;- mimikBlurMode: boolean;onboardingCompleted: boolean;}diff --git a/src/entrypoints/background/actor.ts b/src/entrypoints/background/actor.tsindex a7f3001..4c73838 100644--- a/src/entrypoints/background/actor.ts+++ b/src/entrypoints/background/actor.ts@@ -53,6 +53,9 @@ export function getStateUpdate(): PanelStateUpdate {state: snap.value as CaptureStateValue,stepCount: snap.context.stepCount,currentGuideId: snap.context.currentGuideId,+ // A snapshot persisted before PAUSED existed has no pauseReason key, so+ // normalise it rather than letting `undefined` reach the panel.+ pauseReason: snap.context.pauseReason ?? null,};}diff --git a/src/entrypoints/background/index.ts b/src/entrypoints/background/index.tsindex ef9c541..e87190c 100644--- a/src/entrypoints/background/index.ts+++ b/src/entrypoints/background/index.ts@@ -23,12 +23,20 @@ import {import { logger } from '@/lib/logger';import { onMessage } from '@/lib/messaging';import { broadcastStateToPanel, setupPortListener } from '@/lib/port';+import { TabMessage } from '@/lib/tab-messages';import { recordUpdate } from '@/lib/update-notice';import { getActor, getStateUpdate, initActor, initActorFallback, waitUntilReady } from './actor';import { generateDescriptionOnDemand, generateGuideMetaOnStop, settlePendingDescriptions } from './guide-meta';import { registerNavigationListeners } from './navigation';+import { pauseCapture, resumeFromPause } from './pause';import { handleCaptureStep, handleFinalizeInputStep, handleUpdateInputStep } from './step-pipeline';-import { broadcastStartCapture, broadcastStopCapture, showNotificationOnTab } from './tab-manager';+import {+ broadcastClearBlur,+ broadcastStartCapture,+ broadcastStopCapture,+ isInjectableTab,+ showNotificationOnTab,+} from './tab-manager';import {canStartNarrationNow,getVoiceUpdate,@@ -111,6 +119,9 @@ export default defineBackground(() => {getActor().subscribe(() => broadcastStateToPanel(getStateUpdate()));});+ /** Resume, putting the microphone back if the pause took it away. */+ const resume = () => resumeFromPause(() => void startNarrationIfPossible());+onMessage('getState', async () => {await waitUntilReady();return getStateUpdate();@@ -143,6 +154,7 @@ export default defineBackground(() => {const actor = getActor();const { currentGuideId: guideId, insertTargetGuideId, insertAtIndex } = actor.getSnapshot().context;await broadcastStopCapture();+ await broadcastClearBlur();actor.send({ type: 'STOP_RECORDING' });if (guideId) void stopVoiceNarration(guideId);@@ -163,23 +175,37 @@ export default defineBackground(() => {onMessage('enterBlurMode', async () => {await waitUntilReady();- await broadcastStopCapture();const activeTab = await getActiveTab();- if (activeTab?.id) {- sendMessageToTab(activeTab.id, { type: 'START_BLUR' }).catch(() => {});+ // Blur is a request to mask this page. On a tab that cannot host the+ // overlay — a PDF viewer, a chrome:// page, the dashboard itself — pausing+ // anyway would leave a paused recording with no blur UI and no error, so+ // refuse before touching the machine.+ if (!activeTab?.id || !isInjectableTab(activeTab)) return { entered: false };+ if (!(await pauseCapture('blur'))) return { entered: false };++ try {+ await sendMessageToTab(activeTab.id, { type: TabMessage.START_BLUR });+ } catch (err) {+ logger.warn('enterBlurMode: the tab could not open the overlay', err);+ await resume();+ return { entered: false };}return { entered: true };});onMessage('exitBlurMode', async () => {await waitUntilReady();- await localStorage.set({ mimikBlurMode: false });- const actor = getActor();- const guideId = actor.getSnapshot().context.currentGuideId;- if (guideId) {- await broadcastStartCapture(guideId);- }- return { exited: true };+ return { exited: await resume() };+ });++ onMessage('pauseCapture', async () => {+ await waitUntilReady();+ return { paused: await pauseCapture('manual') };+ });++ onMessage('resumeCapture', async () => {+ await waitUntilReady();+ return { resumed: await resume() };});onMessage('generateGuideDescription', ({ data }) => generateDescriptionOnDemand(data.guideId));diff --git a/src/entrypoints/background/navigation.ts b/src/entrypoints/background/navigation.tsindex 82b9558..6e79b8c 100644--- a/src/entrypoints/background/navigation.ts+++ b/src/entrypoints/background/navigation.ts@@ -1,4 +1,4 @@-import { CaptureState } from '@/core/capture/machine';+import { type CaptureSnapshot, CaptureState } from '@/core/capture/machine';import {getTab,onHistoryStateUpdated,@@ -12,12 +12,23 @@ import { TabMessage } from '@/lib/tab-messages';import { getActor, waitUntilReady } from './actor';import { injectContentScript, isInjectableTab } from './tab-manager';+/**+ * A paused recording is still a recording: the tab keeps navigating, and the URL+ * has to stay current or the next step after the resume is stamped with the page+ * the user was on before pausing — which then drives Guide Me's replay to the+ * wrong page. Content scripts need injecting while paused for the same reason:+ * a tab opened mid-pause would otherwise be deaf to the resume broadcast.+ */+function isLive(state: CaptureSnapshot): boolean {+ return state.value === CaptureState.RECORDING || state.value === CaptureState.PAUSED;+}+export function registerNavigationListeners() {onNavigationCompleted(async (details) => {if (details.frameId !== 0) return;await waitUntilReady();const state = getActor().getSnapshot();- if (state.value === CaptureState.RECORDING) {+ if (isLive(state)) {logger.debug('URL changed (navigation) →', details.url);getActor().send({ type: 'URL_CHANGED', url: details.url });}@@ -27,7 +38,7 @@ export function registerNavigationListeners() {if (details.frameId !== 0) return;await waitUntilReady();const state = getActor().getSnapshot();- if (state.value === CaptureState.RECORDING) {+ if (isLive(state)) {logger.debug('URL changed (SPA pushState) →', details.url);getActor().send({ type: 'URL_CHANGED', url: details.url });}@@ -36,7 +47,7 @@ export function registerNavigationListeners() {onTabActivated(async (activeInfo) => {await waitUntilReady();const state = getActor().getSnapshot();- if (state.value !== CaptureState.RECORDING) return;+ if (!isLive(state)) return;if (!state.context.currentGuideId) return;try {@@ -57,7 +68,7 @@ export function registerNavigationListeners() {if (changeInfo.status !== 'complete') return;await waitUntilReady();const state = getActor().getSnapshot();- if (state.value !== CaptureState.RECORDING) return;+ if (!isLive(state)) return;if (!isInjectableTab(tab)) return;try {diff --git a/src/entrypoints/background/pause.ts b/src/entrypoints/background/pause.tsnew file mode 100644index 0000000..ec8e048--- /dev/null+++ b/src/entrypoints/background/pause.ts@@ -0,0 +1,75 @@+import { CaptureState, type PauseReason } from '@/core/capture/machine';+import { getActiveTab } from '@/lib/browser-api';+import { getActor } from './actor';+import {+ broadcastDismissBlur,+ broadcastStartCapture,+ broadcastStopCaptureAndFlush,+ injectContentScript,+ isInjectableTab,+} from './tab-manager';+import { getVoiceUpdate, stopVoiceNarration } from './voice';++/** Whether narration was live when the recording was paused, so resume can+ * put the microphone back the way the user left it. */+let narrationWasLive = false;++/**+ * Moves RECORDING → PAUSED, then stops every frame and waits for them to drain.+ * Returns false when there is nothing to pause, so a caller never reports a+ * pause the machine did not take.+ *+ * The microphone is part of what "paused" promises. Leaving it live would send+ * whatever is said during the pause to the transcription provider and attribute+ * it to the step captured after the resume — exactly the opposite of what+ * someone pausing over sensitive data expects. Stopping narration here also+ * transcribes what was said *before* the pause, which does belong to the steps+ * already recorded.+ */+export async function pauseCapture(reason: PauseReason): Promise<boolean> {+ const actor = getActor();+ if (actor.getSnapshot().value !== CaptureState.RECORDING) return false;+ actor.send({ type: 'PAUSE_CAPTURE', reason });++ const guideId = actor.getSnapshot().context.currentGuideId;+ narrationWasLive = getVoiceUpdate().phase === 'recording';+ await broadcastStopCaptureAndFlush();+ if (narrationWasLive && guideId) await stopVoiceNarration(guideId);+ return true;+}++/** Moves PAUSED → RECORDING and puts the live frames back to work. */+export async function resumeCapture(onNarrationResume?: () => void): Promise<boolean> {+ const actor = getActor();+ if (actor.getSnapshot().value !== CaptureState.PAUSED) return false;+ actor.send({ type: 'RESUME_CAPTURE' });++ const guideId = actor.getSnapshot().context.currentGuideId;+ if (guideId) {+ // A tab opened or activated during the pause was skipped by the navigation+ // listeners, so it may have no content script to answer START_CAPTURE.+ const activeTab = await getActiveTab();+ if (activeTab?.id && isInjectableTab(activeTab)) await injectContentScript(activeTab.id);+ await broadcastStartCapture(guideId);+ }++ if (narrationWasLive) {+ narrationWasLive = false;+ onNarrationResume?.();+ }+ return true;+}++/**+ * The way back from any pause, however it was entered.+ *+ * Dismissing rather than clearing is the whole point of having both messages:+ * the masks the user just picked have to survive, or the screenshots taken+ * after the resume are unredacted. Only the end of a recording clears them.+ * Both the blur exit and the panel's Resume come through here so there is one+ * place for that decision rather than two that can drift apart.+ */+export async function resumeFromPause(onNarrationResume?: () => void): Promise<boolean> {+ await broadcastDismissBlur();+ return resumeCapture(onNarrationResume);+}diff --git a/src/entrypoints/background/step-pipeline.ts b/src/entrypoints/background/step-pipeline.tsindex c1b109f..5a578c6 100644--- a/src/entrypoints/background/step-pipeline.ts+++ b/src/entrypoints/background/step-pipeline.ts@@ -57,6 +57,21 @@ async function takeScreenshot(stepId: string, meta: ElementMeta): Promise<string}}+/** A keystroke arriving after the user paused must not be written. */+function isRecording(): boolean {+ return getActor().getSnapshot().value === CaptureState.RECORDING;+}++/**+ * A finalize only completes a step the user finished *before* pausing, so it is+ * allowed to land while paused — dropping it would leave that step holding the+ * screenshot taken when the field was still empty. The pause handlers await the+ * flush before opening the blur overlay, so this screenshot cannot catch it.+ */+function isRecordingOrPaused(): boolean {+ return getActor().getSnapshot().value !== CaptureState.IDLE;+}+async function tryAIDescription(stepId: string, domContext: DOMContext) {if (!resolveAiKey(await localStorage.get([...AI_KEY_SETTINGS])).apiKey) return;try {@@ -116,6 +131,7 @@ export async function handleCaptureStep(data: CaptureStepData): Promise<CaptureS}export async function handleUpdateInputStep(stepId: string, description: string, inputValue?: string) {+ if (!isRecording()) return;await updateStepDescription(stepId, description);if (inputValue !== undefined) {await db.steps.update(stepId, { inputValue });@@ -127,6 +143,7 @@ export async function handleFinalizeInputStep(elementMeta: ElementMeta,domContext: DOMContext | undefined,) {+ if (!isRecordingOrPaused()) return;const screenshotId = await takeScreenshot(stepId, elementMeta);const updates: Partial<Step> = { elementMeta };if (screenshotId) updates.screenshotId = screenshotId;diff --git a/src/entrypoints/background/tab-manager.ts b/src/entrypoints/background/tab-manager.tsindex 56d8c2d..b811e71 100644--- a/src/entrypoints/background/tab-manager.ts+++ b/src/entrypoints/background/tab-manager.ts@@ -1,6 +1,6 @@import { executeScript, queryTabs, sendMessageToTab } from '@/lib/browser-api';import { logger } from '@/lib/logger';-import { TabMessage } from '@/lib/tab-messages';+import { TabMessage, type TabMessageType } from '@/lib/tab-messages';export function isInjectableTab(tab: { url?: string; pendingUrl?: string }): boolean {const url = tab.url || tab.pendingUrl || '';@@ -46,6 +46,55 @@ export async function broadcastStartCapture(guideId: string): Promise<void> {}}+/**+ * Closes the blur overlay everywhere, leaving the masks in place. Broadcast+ * rather than aimed at the active tab, because a paused recording re-opens the+ * overlay on whatever page loads, so the overlay may live in a different tab+ * by the time capture resumes.+ */+export async function broadcastDismissBlur(): Promise<void> {+ await broadcastBlur(TabMessage.DISMISS_BLUR);+}++/** Closes the overlay and removes the masks. For the end of a recording. */+export async function broadcastClearBlur(): Promise<void> {+ await broadcastBlur(TabMessage.CLEAR_BLUR);+}++async function broadcastBlur(type: TabMessageType): Promise<void> {+ try {+ const tabs = await queryTabs({});+ for (const tab of tabs) {+ if (tab.id) {+ sendMessageToTab(tab.id, { type }).catch(() => {});+ }+ }+ } catch (err) {+ logger.warn(' broadcastBlur failed', type, err);+ }+}++/** A frame that never answers must not hold a pause open. */+const FLUSH_TIMEOUT_MS = 1500;++/**+ * Stops capture everywhere and waits for the content scripts to answer, which+ * they only do once their queue has drained. Pausing mid-typing would otherwise+ * drop the finalize that writes the step's real screenshot.+ */+export async function broadcastStopCaptureAndFlush(): Promise<void> {+ try {+ const tabs = await queryTabs({});+ const sends = tabs+ .filter((tab): tab is typeof tab & { id: number } => tab.id !== undefined)+ .map((tab) => sendMessageToTab(tab.id, { type: TabMessage.STOP_CAPTURE }).catch(() => {}));+ const timeout = new Promise<void>((resolve) => setTimeout(resolve, FLUSH_TIMEOUT_MS));+ await Promise.race([Promise.allSettled(sends), timeout]);+ } catch (err) {+ logger.warn(' broadcastStopCaptureAndFlush failed', err);+ }+}+export async function broadcastStopCapture(): Promise<void> {try {const tabs = await queryTabs({});diff --git a/src/entrypoints/content.ts b/src/entrypoints/content.tsindex 9d12698..d40131b 100644--- a/src/entrypoints/content.ts+++ b/src/entrypoints/content.ts@@ -1,11 +1,13 @@import { defineContentScript } from 'wxt/utils/define-content-script';import { browser } from '#imports';import { BlurManager } from '@/core/blur/manager';+import { shouldReopenBlur } from '@/core/blur/restore';import { CaptureSession } from '@/core/capture/session';import { updateUrl } from '@/core/capture/spa-nav';import { showStartNotification } from '@/core/capture/start-notification';import { GuideMeController } from '@/core/guideme/content';import { logger } from '@/lib/logger';+import { sendMessage } from '@/lib/messaging';import { TabMessage } from '@/lib/tab-messages';const CLEANUP_EVENT = `mimik_cleanup_${browser.runtime.id}`;@@ -31,8 +33,9 @@ function createTabMessageHandler(session: CaptureSession, guideMe: GuideMeControreturn true;case TabMessage.STOP_CAPTURE:- session.stop();- sendResponse({ stopped: true });+ // Answered only once the queue has drained, so a pause that follows can+ // rely on the final input screenshot already being written.+ session.stop().then(() => sendResponse({ stopped: true }));return true;case TabMessage.URL_CHANGED:@@ -59,6 +62,16 @@ function createTabMessageHandler(session: CaptureSession, guideMe: GuideMeControsendResponse({ started: true });return true;+ case TabMessage.DISMISS_BLUR:+ blurManager.dismiss();+ sendResponse({ dismissed: true });+ return true;++ case TabMessage.CLEAR_BLUR:+ blurManager.stop();+ sendResponse({ stopped: true });+ return true;+default:return false;}@@ -74,9 +87,19 @@ export default defineContentScript({main() {document.dispatchEvent(new CustomEvent(CLEANUP_EVENT));- const session = new CaptureSession();- const guideMe = new GuideMeController();const blurManager = new BlurManager();+ // A recording paused for blur keeps the overlay alive across navigation:+ // without this, the page that loads next has no Done button, so the user+ // would be stuck paused with no way back from the page itself. The state is+ // re-read rather than trusted, because the boot round trip is long enough+ // for a Resume to land in the middle of it.+ const session = new CaptureSession(async (state) => {+ if (!shouldReopenBlur(state, window.self === window.top)) return;+ const current = await sendMessage('getState', undefined).catch(() => null);+ if (!current || !shouldReopenBlur(current, true)) return;+ blurManager.start();+ });+ const guideMe = new GuideMeController();const handleTabMessage = createTabMessageHandler(session, guideMe, blurManager);document.addEventListener(CLEANUP_EVENT, () => {diff --git a/src/lib/messaging.ts b/src/lib/messaging.tsindex eeda699..e6ef5de 100644--- a/src/lib/messaging.ts+++ b/src/lib/messaging.ts@@ -1,12 +1,13 @@import { defineExtensionMessaging } from '@webext-core/messaging';import type { DOMContext } from '@/core/capture/dom/context';-import type { CaptureStateValue } from '@/core/capture/machine';+import type { CaptureStateValue, PauseReason } from '@/core/capture/machine';import type { ElementMeta } from '@/core/guides/types';export interface GetStateResponse {state: CaptureStateValue;stepCount: number;currentGuideId: string | null;+ pauseReason: PauseReason | null;}export interface StartRecordingData {@@ -133,6 +134,14 @@ export interface ExitBlurModeResponse {exited: boolean;}+export interface PauseCaptureResponse {+ paused: boolean;+}++export interface ResumeCaptureResponse {+ resumed: boolean;+}+interface MimikProtocol {getState(): GetStateResponse;startRecording(data: StartRecordingData): StartRecordingResponse;@@ -146,6 +155,8 @@ interface MimikProtocol {guideMeGoTo(data: GuideMe_GoToData): GuideMe_GoToResponse;enterBlurMode(): EnterBlurModeResponse;exitBlurMode(): ExitBlurModeResponse;+ pauseCapture(): PauseCaptureResponse;+ resumeCapture(): ResumeCaptureResponse;startNarration(): StartNarrationResponse;generateGuideDescription(data: GenerateGuideDescriptionData): GenerateGuideDescriptionResponse;validateApiKey(data: ValidateApiKeyData): ValidateApiKeyResponse;diff --git a/src/lib/port.ts b/src/lib/port.tsindex e6886ae..41f7f6b 100644--- a/src/lib/port.ts+++ b/src/lib/port.ts@@ -1,6 +1,6 @@import { browser } from '#imports';import type { AiFailureReason } from '@/core/capture/ai/errors';-import type { CaptureStateValue } from '@/core/capture/machine';+import type { CaptureStateValue, PauseReason } from '@/core/capture/machine';import { logger } from '@/lib/logger';import type { VoiceErrorReason } from '@/lib/voice-messages';@@ -12,6 +12,7 @@ export interface PanelStateUpdate {state: CaptureStateValue;stepCount: number;currentGuideId: string | null;+ pauseReason: PauseReason | null;}export type VoicePhase = 'idle' | 'recording' | 'transcribing' | 'error';diff --git a/src/lib/tab-messages.ts b/src/lib/tab-messages.tsindex 3d8d95f..7307e42 100644--- a/src/lib/tab-messages.ts+++ b/src/lib/tab-messages.ts@@ -7,6 +7,8 @@ export const TabMessage = {SHOW_NOTIFICATION: 'SHOW_NOTIFICATION',GUIDEME_STOP: 'GUIDEME_STOP',START_BLUR: 'START_BLUR',+ DISMISS_BLUR: 'DISMISS_BLUR',+ CLEAR_BLUR: 'CLEAR_BLUR',} as const;export type TabMessageType = (typeof TabMessage)[keyof typeof TabMessage];diff --git a/src/locales/de.yml b/src/locales/de.ymlindex 76e29e2..ff9e5ab 100644--- a/src/locales/de.yml+++ b/src/locales/de.yml@@ -71,6 +71,9 @@ guidemeCompletion:recording:capturePaused: Aufnahme pausiert+ capturePausedBlur: "Smart Blur · Aufnahme pausiert"+ pauseCapture: Aufnahme pausieren+ resumeCapture: Aufnahme fortsetzenrecording: "Aufnahme \xB7 $1 Schritt"recordingPlural: "Aufnahme \xB7 $1 Schritte"readyTitle: Bereit zur Aufnahme!@@ -517,6 +520,7 @@ voice:turnOn: Sprachkommentar einschaltenturnOff: Sprachkommentar ausschaltenneedsApiKey: Füge in den Einstellungen einen Transkriptions-API-Schlüssel hinzu, um zu kommentieren+ pausedWithCapture: Die Kommentierung ist mit der Aufnahme pausiertmicStarting: "Mikrofon wird gestartet…"micHearing: Ich höre dichmicQuiet: Kein Tondiff --git a/src/locales/en.yml b/src/locales/en.ymlindex 5d9aa11..7653e90 100644--- a/src/locales/en.yml+++ b/src/locales/en.yml@@ -71,6 +71,9 @@ guidemeCompletion:recording:capturePaused: Capture paused+ capturePausedBlur: Blur mode · capture paused+ pauseCapture: Pause capture+ resumeCapture: Resume capturerecording: "Recording \xB7 $1 step"recordingPlural: "Recording \xB7 $1 steps"readyTitle: Ready to capture!@@ -516,6 +519,7 @@ voice:turnOn: Turn on voice narrationturnOff: Turn off voice narrationneedsApiKey: Add a transcription API key in Settings to narrate+ pausedWithCapture: Narration is paused with the capturemicStarting: Starting microphone...micHearing: Hearing youmicQuiet: No sounddiff --git a/src/locales/es.yml b/src/locales/es.ymlindex cd18be3..6b1a59e 100644--- a/src/locales/es.yml+++ b/src/locales/es.yml@@ -71,6 +71,9 @@ guidemeCompletion:recording:capturePaused: Captura en pausa+ capturePausedBlur: "Desenfoque inteligente · captura en pausa"+ pauseCapture: Pausar captura+ resumeCapture: Reanudar capturarecording: "Grabando \xB7 $1 paso"recordingPlural: "Grabando \xB7 $1 pasos"readyTitle: "¡Listo para grabar!"@@ -516,6 +519,7 @@ voice:turnOn: "Activar narración por voz"turnOff: "Desactivar narración por voz"needsApiKey: "Añade una clave API de transcripción en Ajustes para narrar"+ pausedWithCapture: "La narración está en pausa junto con la captura"micStarting: "Iniciando el micrófono..."micHearing: Te estamos oyendomicQuiet: Sin sonidodiff --git a/src/locales/fr.yml b/src/locales/fr.ymlindex 629ff92..43025f3 100644--- a/src/locales/fr.yml+++ b/src/locales/fr.yml@@ -71,6 +71,9 @@ guidemeCompletion:recording:capturePaused: Capture en pause+ capturePausedBlur: Mode flou · capture en pause+ pauseCapture: Mettre la capture en pause+ resumeCapture: Reprendre la capturerecording: "Enregistrement \xB7 $1 étape"recordingPlural: "Enregistrement \xB7 $1 étapes"readyTitle: "Prêt à capturer !"@@ -516,6 +519,7 @@ voice:turnOn: "Activer la narration vocale"turnOff: "Désactiver la narration vocale"needsApiKey: "Ajoutez une clé API de transcription dans les paramètres pour commenter"+ pausedWithCapture: "La narration est en pause avec la capture"micStarting: "Démarrage du micro..."micHearing: Nous vous entendonsmicQuiet: Aucun sondiff --git a/src/locales/pt-BR.yml b/src/locales/pt-BR.ymlindex 0e4b1cf..34d5e75 100644--- a/src/locales/pt-BR.yml+++ b/src/locales/pt-BR.yml@@ -71,6 +71,9 @@ guidemeCompletion:recording:capturePaused: Captura em pausa+ capturePausedBlur: Modo desfoque · captura em pausa+ pauseCapture: Pausar captura+ resumeCapture: Retomar capturarecording: "Gravando \xB7 $1 passo"recordingPlural: "Gravando \xB7 $1 passos"readyTitle: "Pronto pra gravar!"@@ -516,6 +519,7 @@ voice:turnOn: "Ligar narração por voz"turnOff: "Desligar narração por voz"needsApiKey: "Adicione uma chave API de transcrição nos Ajustes pra narrar"+ pausedWithCapture: "A narração está em pausa junto com a captura"micStarting: "Ligando o microfone..."micHearing: "Tô te ouvindo"micQuiet: Sem somdiff --git a/src/locales/zh-CN.yml b/src/locales/zh-CN.ymlindex e8fb4ba..cb0887d 100644--- a/src/locales/zh-CN.yml+++ b/src/locales/zh-CN.yml@@ -71,6 +71,9 @@ guidemeCompletion:recording:capturePaused: 捕获已暂停+ capturePausedBlur: 模糊模式 · 捕获已暂停+ pauseCapture: 暂停捕获+ resumeCapture: 继续捕获recording: "正在录制 · $1 个步骤"recordingPlural: "正在录制 · $1 个步骤"readyTitle: 已准备好捕获!@@ -516,6 +519,7 @@ voice:turnOn: 开启语音讲解turnOff: 关闭语音讲解needsApiKey: 在设置中添加转写 API 密钥以使用语音讲解+ pausedWithCapture: 语音讲解已随捕获一起暂停micStarting: 正在启动麦克风...micHearing: 正在听你说话micQuiet: 没有声音diff --git a/src/ui/sidepanel/App.tsx b/src/ui/sidepanel/App.tsxindex 67e3593..4fe7edf 100644--- a/src/ui/sidepanel/App.tsx+++ b/src/ui/sidepanel/App.tsx@@ -1,7 +1,7 @@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 { CaptureState, type PauseReason } from '@/core/capture/machine';import { isRecordableUrl } from '@/core/capture/recordable-tabs';import type { GuideMeSession } from '@/core/guideme/session';import { SESSION_KEY } from '@/core/guideme/session';@@ -96,6 +96,8 @@ export default function App() {const [voice, setVoice] = useState<PanelVoiceUpdate>({ type: 'VOICE_UPDATE', phase: 'idle' });const [aiFailure, setAiFailure] = useState<PanelAiUpdate | null>(null);const [voiceStarted, setVoiceStarted] = useState(false);+ const [paused, setPaused] = useState(false);+ const [pauseReason, setPauseReason] = useState<PauseReason | null>(null);useEffect(() => {const disconnect = connectToBackground({@@ -112,8 +114,12 @@ export default function App() {},onDisconnect: () => setIsAlive(false),onStateUpdate: (update) => {- if (update.state === CaptureState.RECORDING) {- setIsRecording(true);+ const live = update.state === CaptureState.RECORDING || update.state === CaptureState.PAUSED;+ const isPaused = update.state === CaptureState.PAUSED;+ setPaused(isPaused);+ setPauseReason(isPaused ? (update.pauseReason ?? null) : null);+ if (live) {+ setIsRecording(update.state === CaptureState.RECORDING);setAiFailure(null);const guideId = update.currentGuideId;if (guideId) {@@ -213,7 +219,16 @@ export default function App() {function renderView() {if (view.name === 'recording') {- return <RecordingView guideId={view.guideId} onStop={handleStopRecording} voice={voice} aiFailure={aiFailure} />;+ return (+ <RecordingView+ guideId={view.guideId}+ onStop={handleStopRecording}+ voice={voice}+ aiFailure={aiFailure}+ paused={paused}+ pauseReason={pauseReason}+ />+ );}if (view.name === 'guideme') {