Webcam is not working on my mac pro

In p5js editor, I wanted to test the example called “capture” to turn on my webcam on my mac pro. The code must be correct since I used the example that already existed, but the camera is not turning on and I do not know why. It works in the web editor in p5.js, but not on the editor on my computer.

the console says,

“constraintName”: “”,
“message”: “”,
“name”: “InvalidStateError”

let capture;
function setup() {
createCanvas(390, 240);
capture = createCapture(VIDEO);
capture.size(320, 240);

function draw() {
image(capture, 0, 0, 320, 240);

Does your website allow the camera to be used?

Yes, the webcam works fine with the web editor!