Skip to content

Commit d5a3087

Browse files
authored
add friendly error to createCapture()
1 parent cf94f56 commit d5a3087

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/dom/dom.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2438,7 +2438,15 @@ p5.prototype.createCapture = function(...args) {
24382438
catch(err) {
24392439
domElement.src = stream;
24402440
}
2441-
}, console.error);
2441+
}).catch(e => {
2442+
2443+
if (e.name === 'NotFoundError')
2444+
p5._friendlyError('No webcam found on this device', 'createCapture');
2445+
if (e.name === 'NotAllowedError')
2446+
p5._friendlyError('Access to the camera was denied', 'createCapture');
2447+
2448+
console.error(e);
2449+
});
24422450

24432451
const videoEl = addElement(domElement, this, true);
24442452
videoEl.loadedmetadata = false;

0 commit comments

Comments
 (0)