Show camera permission only once per session on website #946
Unanswered
pklingler87
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone!
Maybe someone can help me. I want to use the QR code scanner on a website and it works perfectly so far. The only problem is that every time you use the QR code scanner you have to allow access to the camera. Is there a way to request access the first time you use it and then save it for the website session so that I don't always have to confirm access?
This is my code snippet:
function domReady(fn) {
if (
document.readyState === "complete" ||
document.readyState === "interactive"
) {
setTimeout(fn, 1000);
} else {
document.addEventListener("DOMContentLoaded", fn);
}
}
domReady(function () {
// If found your QR code
function onScanSuccess(decodeText, decodeResult) {
// Stop the scanner
htmlscanner.clear().then(_ => {
console.log("QR code scanning stopped.");
// Redirect to the scanned URL
// window.location.href = decodeText;
window.location.href = "https://my-domain.com/?activate=" + decodeText;
}).catch(error => {
console.error("Failed to clear the scanner. Reason: ", error);
});
}
});
Thanks for helping!
Beta Was this translation helpful? Give feedback.
All reactions