1

How to use iOS and macOS's latest feature of Continuity Camera feature with JavaScript, or how to avoid it from popping up in the process of requesting media devices, i.e. navigator.mediaDevices.getUserMedia({ video: true })? - as it actually breaks this code on Chrome whenever my iPhone is close to the laptop with the error Uncaught (in promise) DOMException: Could not start video source, even after I tried to set chrome://settings/content/camera to the original FaceTime HD Camera - seems Chrome just keeps trying to request iPhone as the webcam.


Update - To avoid Continuity Camera, I use this quick patch to prefer the FaceTime Camera if possible (while it would still be better and cool to be able to use iPhone whenever needed)

let preferredDeviceId = undefined
const availableDevices = await navigator.mediaDevices.enumerateDevices()
if (availableDevices.length > 1)
    for (let d of availableDevices)
        if (d.label.includes('FaceTime'))
            preferredDeviceId = d.deviceId

await navigator.mediaDevices.getUserMedia({
    video: {
        deviceId: preferredDeviceId,
    }
})
j22
  • 71
  • 1
  • 7
  • I tried to use `enumerateDevices()` but I'm not getting the continuity camera, are you still able to get it with no additional steps? – neobits Dec 15 '22 at 11:14
  • No, I wasn't able to either. Sorry for the confusion, but I think the problem above was Chrome thought CC was registered and fed it the default if you try to `getUserMedia` directly, while JavaScript couldn't load it, so I added the code snippet to prefer FaceTime camera instead of having Chrome to give a default. – j22 Dec 16 '22 at 18:43

0 Answers0