Skip to content

Commit 1b140e3

Browse files
authored
Merge pull request #6961 from mdb0/main
add friendly error to createCapture()
2 parents bcb77cf + ef9af73 commit 1b140e3

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/dom/dom.js

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

24432450
const videoEl = addElement(domElement, this, true);
24442451
videoEl.loadedmetadata = false;

0 commit comments

Comments
 (0)