Discussions

Ask a Question
Back to All

Permission Error When Accessing Camera in Servicem8 Add-On Using navigator.mediaDevices.getUserMedia()

I am developing an add-on that requires camera permissions to enable users to add images and scan barcodes. However, I am encountering a permission error when trying to access the camera. This issue only occurs when running the add-on in Servicem8, while it works fine in other environments.

The specific line of code causing the issue is:

navigator.mediaDevices.getUserMedia({ video:true, audio:true })

This line is supposed to prompt the user for camera permissions upon a button click and then activate the camera. The problem persists across both desktop and mobile versions of the Chrome browser.
What could be causing this issue? Is it possible that Servicem8 is blocking the camera permissions? Here is the minimal code necessary to reproduce the problem:

<button onclick="accessCamera()">Access Camera</button>

<script>
    function accessCamera() {
        navigator.mediaDevices.getUserMedia({ video:true, audio:true })
            .then(function(stream) {
                /* use the stream */
            })
            .catch(function(err) {
                /* handle the error */
            });
    }
</script>