Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

fix(frontend): don't crash app when Web Speech API access throws (#11618)

Jay Dorsey01ae688b58a1
diff --git a/frontend/src/container/AIAssistant/hooks/useSpeechRecognition.ts b/frontend/src/container/AIAssistant/hooks/useSpeechRecognition.ts
index e6562861de..8ad3c96ae1 100644
--- a/frontend/src/container/AIAssistant/hooks/useSpeechRecognition.ts
+++ b/frontend/src/container/AIAssistant/hooks/useSpeechRecognition.ts
@@ -40,13 +40,31 @@ type SpeechRecognitionConstructor = new () => ISpeechRecognition;
// ── Vendor-prefix shim for Safari / older browsers ────────────────────────────
-const SpeechRecognitionAPI: SpeechRecognitionConstructor | null =
- typeof window !== 'undefined'
- ? // eslint-disable-next-line @typescript-eslint/no-explicit-any
- ((window as any).SpeechRecognition ??
+// Some hardened/enterprise browsers install a getter
+// on window.SpeechRecognition that THROWS on access ("Web Speech API is disabled
+// due to your security policy") instead of leaving the property undefined.
+// Because this resolves at module-evaluation time, an uncaught throw here aborts
+// the entire bundle and the app renders a blank page. Read defensively so a
+// throwing getter degrades to "unsupported" rather than crashing the app.
+function resolveSpeechRecognitionAPI(): SpeechRecognitionConstructor | null {
+ if (typeof window === 'undefined') {
+ return null;
+ }
+ try {
+ return (
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ (window as any).SpeechRecognition ??
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
(window as any).webkitSpeechRecognition ??
- null)
- : null;
+ null
+ );
+ } catch {
+ return null;
+ }
+}
+
+const SpeechRecognitionAPI: SpeechRecognitionConstructor | null =
+ resolveSpeechRecognitionAPI();
export type SpeechRecognitionError =
| 'not-supported'