Skip to content

fix(tts): guard SpeechSynthesisUtterance addEventListener calls - #1692

Merged
feruzm merged 2 commits into
developfrom
seer/fix/tts-utterance-event-listener-guard
Aug 26, 2026
Merged

fix(tts): guard SpeechSynthesisUtterance addEventListener calls#1692
feruzm merged 2 commits into
developfrom
seer/fix/tts-utterance-event-listener-guard

Conversation

@sentry

@sentry sentry Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

This PR addresses a TypeError: r.addEventListener is not a function occurring in use-tts.ts when SpeechSynthesisUtterance.addEventListener is called unconditionally.

The root cause is that in some environments (e.g., older Safari, certain Android WebViews), SpeechSynthesisUtterance might not expose addEventListener as it doesn't extend EventTarget in those specific contexts. Calling an undefined method results in the observed TypeError.

The fix involves adding a typeof utterance.addEventListener === "function" check before attempting to use addEventListener. If addEventListener is available, it is used as before. Otherwise, the code falls back to assigning event handlers directly to the onstart, onend, onpause, and onresume properties of the SpeechSynthesisUtterance object. This approach aligns with existing defensive patterns in the codebase, such as those found in speech.ts for window.speechSynthesis.

Fixes ECENCY-NEXT-1GNS

This PR was automatically generated by Sentry. You can adjust this setting at any time.

sentry Bot and others added 2 commits August 26, 2026 10:53
The Sentry event is Chrome 138, not an old browser: a privacy shim replaced
SpeechSynthesisUtterance with a plain object, so the guard is defensive
against shims rather than legacy engines. The effect cleanup had the same
class of hazard: a bare speechSynthesis identifier is a ReferenceError in an
environment where only the constructor is shimmed into existence.

Spec covers the EventTarget path, the shim fallback driving the same state
and cleanup with no speechSynthesis global.
@feruzm
feruzm merged commit 6f96304 into develop Aug 26, 2026
7 checks passed
@feruzm
feruzm deleted the seer/fix/tts-utterance-event-listener-guard branch August 26, 2026 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant