Skip to content

Comments

fix: guard getUserMedia call against undefined mediaDevices in non-secure contexts#78

Merged
jamiepine merged 1 commit intojamiepine:mainfrom
tomasmach:fix/getUserMedia-undefined-check
Feb 23, 2026
Merged

fix: guard getUserMedia call against undefined mediaDevices in non-secure contexts#78
jamiepine merged 1 commit intojamiepine:mainfrom
tomasmach:fix/getUserMedia-undefined-check

Conversation

@tomasmach
Copy link
Contributor

Summary

  • Adds a guard check for navigator.mediaDevices and navigator.mediaDevices.getUserMedia before attempting to access the microphone in AudioSampleRecording.tsx
  • Prevents a crash (Cannot read properties of undefined (reading 'getUserMedia')) that occurs in non-secure (HTTP) contexts where navigator.mediaDevices is undefined
  • The error surfaced when closing the voice profile edit screen in remote/non-HTTPS setups (e.g. Windows desktop app pointing at a remote server)

Root cause

navigator.mediaDevices is only available in secure contexts (HTTPS or localhost). On plain HTTP, it is undefined. The cleanup effect unconditionally called .getUserMedia(...) on mount, causing an unhandled exception when the component unmounted — even if the user never interacted with the record tab.

Fix

  useEffect(() => {
    if (!showWaveform) return;
+   if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) return;

Credit

Bug found and fix identified by AuroraSkye on the Voicebox Discord. Thank you!

Copilot AI added a commit to Patrick-DE/voicebox that referenced this pull request Feb 19, 2026
…ne#88, jamiepine#91, jamiepine#95, jamiepine#97)

Co-authored-by: Patrick-DE <14962702+Patrick-DE@users.noreply.github.com>
@jamiepine jamiepine merged commit 46b8f6b into jamiepine:main Feb 23, 2026
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.

2 participants