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