| 63 | |
| 64 | /** Resolves the recognizer constructor, applying the Chromium brand allowlist. */ |
| 65 | const getRecognitionCtor = (): SpeechRecognitionConstructor | null => { |
| 66 | if (typeof window === 'undefined') { |
| 67 | return null; |
| 68 | } |
| 69 | const ctor = window.SpeechRecognition ?? window.webkitSpeechRecognition ?? null; |
| 70 | if (!ctor) { |
| 71 | return null; |
| 72 | } |
| 73 | const brands = navigator.userAgentData?.brands; |
| 74 | if (brands && !brands.some(b => VOICE_INPUT_CHROMIUM_BROWSERS.has(b.brand))) { |
| 75 | return null; |
| 76 | } |
| 77 | return ctor; |
| 78 | }; |
| 79 | |
| 80 | /** SpeechRecognition requires a secure context (HTTPS / localhost). */ |
| 81 | const isSecureVoiceContext = (): boolean => |