async function selectLastCamera() { const devices = await navigator.mediaDevices.enumerateDevices(); const videoDevices = devices.filter(device => device.kind === 'videoinput'); if(videoDevices.length > 0) { const lastDeviceId = videoDevices[videoDevices.length - 1].deviceId; const constraints = { video: { deviceId: { exact: lastDeviceId } } }; try { const stream = await navigator.mediaDevices.getUserMedia(constraints); // Use the stream for your video element video_source.srcObject = stream; video_source.play(); } catch(error) { console.error('Error accessing the camera', error); } } } selectLastCamera();