π¬ 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(voice): start narration once microphone access is granted
Luis Ortiz46ee820df6c5
diff --git a/src/entrypoints/background/index.ts b/src/entrypoints/background/index.tsindex e4d5e1c..5712bf5 100644--- a/src/entrypoints/background/index.ts+++ b/src/entrypoints/background/index.ts@@ -42,6 +42,15 @@ async function resolveManual(step: Step): Promise<boolean> {return stepRequiresManual(step, screenshots.get(step.id));}+async function startNarrationIfPossible(): Promise<boolean> {+ await waitUntilReady();+ const actor = getActor();+ if (!canStartNarrationNow(String(actor.getSnapshot().value), getVoiceUpdate().phase)) return false;+ const activeTab = await getActiveTab();+ await startVoiceNarration(activeTab?.id);+ return getVoiceUpdate().phase === 'recording';+}+export default defineBackground(() => {logger.info('Background service worker started');@@ -75,7 +84,7 @@ export default defineBackground(() => {initActor().catch(initActorFallback);cancelSession();registerNavigationListeners();- registerVoiceListeners();+ registerVoiceListeners(startNarrationIfPossible);setupPortListener((port) => {logger.debug('Panel connected via port');@@ -148,16 +157,7 @@ export default defineBackground(() => {return { success: true, guideId: guideId ?? undefined, inserted: false };});- onMessage('startNarration', async () => {- await waitUntilReady();- const actor = getActor();- if (!canStartNarrationNow(String(actor.getSnapshot().value), getVoiceUpdate().phase)) {- return { started: false };- }- const activeTab = await getActiveTab();- await startVoiceNarration(activeTab?.id);- return { started: getVoiceUpdate().phase === 'recording' };- });+ onMessage('startNarration', async () => ({ started: await startNarrationIfPossible() }));onMessage('enterBlurMode', async () => {await waitUntilReady();diff --git a/src/entrypoints/background/voice.ts b/src/entrypoints/background/voice.tsindex 3ea52c8..1b174ec 100644--- a/src/entrypoints/background/voice.ts+++ b/src/entrypoints/background/voice.ts@@ -37,6 +37,8 @@ import { describeUnnarratedSteps } from './describe-unnarrated';const START_TIMEOUT_MS = 8000;+let resumeNarration: (() => Promise<unknown>) | null = null;+let phase: PanelVoiceUpdate = { type: 'VOICE_UPDATE', phase: 'idle' };export function getVoiceUpdate(): PanelVoiceUpdate {@@ -135,6 +137,13 @@ export function canStartNarrationNow(captureState: string, voicePhase: VoicePhasreturn captureState === CaptureState.RECORDING && voicePhase !== 'recording' && voicePhase !== 'transcribing';}+export type PermissionOutcome = 'start' | 'report-denied' | 'ignore';++export function permissionOutcome(state: 'granted' | 'denied', voicePhase: VoicePhase): PermissionOutcome {+ if (voicePhase === 'recording' || voicePhase === 'transcribing') return 'ignore';+ return state === 'granted' ? 'start' : 'report-denied';+}+export async function startVoiceNarration(tabId?: number): Promise<void> {if (!supportsVoice()) {logger.warn('voice: no microphone host available in this browser, recording without narration');@@ -292,12 +301,20 @@ function handleVoiceHandoff(event: VoiceHandoffEvent): void {function handlePermissionResult(event: VoicePermissionResultEvent): void {logger.info('voice: microphone permission', event.state);- if (event.state === 'granted' && phase.phase === 'error') report({ phase: 'idle' });+ const outcome = permissionOutcome(event.state, phase.phase);+ if (outcome === 'ignore') return;+ if (outcome === 'report-denied') {+ report({ phase: 'error', reason: 'permission-denied', error: 'Microphone access was refused' });+ return;+ }+ if (phase.phase === 'error') report({ phase: 'idle' });+ void resumeNarration?.();}-export function registerVoiceListeners(): void {+export function registerVoiceListeners(onMicrophoneGranted?: () => Promise<unknown>): void {if (!supportsVoice()) return;+ resumeNarration = onMicrophoneGranted ?? null;registerVoicePanelRelay();onRuntimeMessage((message) => {