You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR addresses a TypeError: undefined is not an object (evaluating 'Object.getPrototypeOf(voice)') that occurred when readVoices() was called, specifically on iOS Brave (and potentially other WebKit-based browsers).
The root cause was that window.speechSynthesis.getVoices() on these platforms could return an array-like object containing uninitialized or undefined entries. The subsequent .filter(Boolean) call would then cause the JavaScript engine to attempt Object.getPrototypeOf() on these undefined elements, leading to a crash.
The fix involves two steps:
Using Array.from(window.speechSynthesis.getVoices() ?? []) to safely convert the potentially non-standard SpeechSynthesisVoiceList into a proper JavaScript array, handling cases where getVoices() might return null or undefined itself (though unlikely).
Replacing .filter(Boolean) with a more robust type-guard filter: (v): v is SpeechSynthesisVoice => v != null && typeof v === "object". This explicitly checks for null and undefined values, preventing the TypeError by ensuring Object.getPrototypeOf() is only called on valid SpeechSynthesisVoice objects.
This change ensures the text-to-speech functionality works reliably on affected browsers without impacting behavior on compliant browsers.
Column 45 on line 18 is the ( of getVoices(). .filter starts at column 48. So the throw happens inside window.speechSynthesis.getVoices(), before any filtering runs. The variable in the message, voice, does not exist in our source: it is iOS Brave's fingerprint-farbling shim, which wraps getVoices and builds its fake voice from Object.getPrototypeOf(voices[0]). On iOS the first call routinely returns an empty list, so the shim dereferences undefined.
Two consequences:
Array.from(window.speechSynthesis.getVoices() ?? []) still calls getVoices() first, so it throws exactly as before.
.filter(Boolean) does not throw on undefined entries in the first place, so it was never the site. [undefined, {...}, null].filter(Boolean) returns [{...}].
Fixed in #1526 by reading the voice list through a try/catch that returns [], which is the state the voiceschanged listener and the poll fallback already handle. Regression tests added to apps/web/src/specs/utils/speech.spec.ts; they fail on develop with the exact production error.
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
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: undefined is not an object (evaluating 'Object.getPrototypeOf(voice)')that occurred whenreadVoices()was called, specifically on iOS Brave (and potentially other WebKit-based browsers).The root cause was that
window.speechSynthesis.getVoices()on these platforms could return an array-like object containing uninitialized orundefinedentries. The subsequent.filter(Boolean)call would then cause the JavaScript engine to attemptObject.getPrototypeOf()on theseundefinedelements, leading to a crash.The fix involves two steps:
Array.from(window.speechSynthesis.getVoices() ?? [])to safely convert the potentially non-standardSpeechSynthesisVoiceListinto a proper JavaScript array, handling cases wheregetVoices()might returnnullorundefineditself (though unlikely)..filter(Boolean)with a more robust type-guard filter:(v): v is SpeechSynthesisVoice => v != null && typeof v === "object". This explicitly checks fornullandundefinedvalues, preventing theTypeErrorby ensuringObject.getPrototypeOf()is only called on validSpeechSynthesisVoiceobjects.This change ensures the text-to-speech functionality works reliably on affected browsers without impacting behavior on compliant browsers.
Fixes ECENCY-NEXT-1GMR
This PR was automatically generated by Sentry. You can adjust this setting at any time.