Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Alewa's avatar
Level 2

Laravel 11 with inertia js undefined (reading 'getUserMedia')

I am getting error code in my laravel 11 inertia js project, in chrome browser, this is the error TypeError: Cannot read properties of undefined (reading 'getUserMedia') and in firefox this is the error TypeError: navigator.mediaDevices is undefined This is my AudioRecorder.jsx file

import { useState } from "react";
import { MicrophoneIcon, StopCircleIcon } from "@heroicons/react/24/solid";

const AudioRecorder = ({ fileReady }) => {
    const [mediaRecorder, setMediaRecorder] = useState(null);
    const [recording, setRecording] = useState(false);

    const onMicrophoneClick = async () => {
        if (recording) {
            setRecording(false);
            if (mediaRecorder) {
                mediaRecorder.stop();
                setMediaRecorder(null);
            }
            return;
        }
        setRecording(true);

        try {
            const stream = await navigator.mediaDevices.getUserMedia({
                audio: true,
            });
            const newMediaRecorder = new MediaRecorder(stream);
            const chunks = [];

            newMediaRecorder.addEventListener("dataavailable", (event) => {
                chunks.push(event.data);
            });

            newMediaRecorder.addEventListener("stop", () => {
                let audioBlob = new Blob(chunks, {
                    type: "audio/ogg; codecs=opus",
                });

                let audioFile = new File([audioBlob], "recorded_audio.ogg", {
                    type: "audio/ogg; codecs=opus",
                });

                const url = URL.createObjectURL(audioFile);

                fileReady(audioFile, url);
            });

            newMediaRecorder.start();
            setMediaRecorder(newMediaRecorder);
        } catch (error) {
            setRecording(false);
            console.error("Error accessing microphone:", error);
        }
    };

    return (
        <button
            onClick={onMicrophoneClick}
            className="p-1 text-gray-400 hover:text-gray-200"
        >
            {recording && <StopCircleIcon className="w-6 text-red-600" />}
            {!recording && <MicrophoneIcon className="w-6" />}
        </button>
    );
};

export default AudioRecorder;

Any help?

0 likes
6 replies
Alewa's avatar
Level 2

@gych I have try opera browser and edge browser but still getting that error.

gych's avatar

@Alewa Have you already tried on a secure https connection ?

Alewa's avatar
Level 2

@gych no, I am working on a local xampp server, but just want to test, so i will know if the error is not coming from my code.

Please or to participate in this conversation.