fix(tts): guard SpeechSynthesisUtterance addEventListener calls - #1692
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses a
TypeError: r.addEventListener is not a functionoccurring inuse-tts.tswhenSpeechSynthesisUtterance.addEventListeneris called unconditionally.The root cause is that in some environments (e.g., older Safari, certain Android WebViews),
SpeechSynthesisUtterancemight not exposeaddEventListeneras it doesn't extendEventTargetin those specific contexts. Calling an undefined method results in the observedTypeError.The fix involves adding a
typeof utterance.addEventListener === "function"check before attempting to useaddEventListener. IfaddEventListeneris available, it is used as before. Otherwise, the code falls back to assigning event handlers directly to theonstart,onend,onpause, andonresumeproperties of theSpeechSynthesisUtteranceobject. This approach aligns with existing defensive patterns in the codebase, such as those found inspeech.tsforwindow.speechSynthesis.Fixes ECENCY-NEXT-1GNS
This PR was automatically generated by Sentry. You can adjust this setting at any time.