diff --git a/src/html5-qrcode-scanner.ts b/src/html5-qrcode-scanner.ts
index 9cb5b89..628064d 100644
--- a/src/html5-qrcode-scanner.ts
+++ b/src/html5-qrcode-scanner.ts
@@ -178,6 +178,7 @@ export class Html5QrcodeScanner {
private persistedDataManager: PersistedDataManager;
private scanTypeSelector: ScanTypeSelector;
private logger: Logger;
+ private isCleared = false;
// Initally null fields.
private html5Qrcode: Html5Qrcode | undefined;
@@ -232,6 +233,7 @@ export class Html5QrcodeScanner {
public render(
qrCodeSuccessCallback: QrcodeSuccessCallback,
qrCodeErrorCallback: QrcodeErrorCallback | undefined) {
+ this.isCleared = false;
this.lastMatchFound = null;
// Add wrapper to success callback.
@@ -324,6 +326,8 @@ export class Html5QrcodeScanner {
* fails otherwise.
*/
public clear(): Promise {
+ this.isCleared = true;
+
const emptyHtmlContainer = () => {
const mainContainer = document.getElementById(this.elementId);
if (mainContainer) {
@@ -546,6 +550,9 @@ export class Html5QrcodeScanner {
}
Html5Qrcode.getCameras().then((cameras) => {
+ if ($this.isCleared) {
+ return;
+ }
// By this point the user has granted camera permissions.
$this.persistedDataManager.setHasPermission(
/* hasPermission */ true);
@@ -612,6 +619,9 @@ export class Html5QrcodeScanner {
&& this.persistedDataManager.hasCameraPermissions()) {
CameraPermissions.hasPermissions().then(
(hasPermissions: boolean) => {
+ if ($this.isCleared) {
+ return;
+ }
if (hasPermissions) {
$this.createCameraListUi(
scpCameraScanRegion, requestPermissionContainer);
@@ -964,6 +974,9 @@ export class Html5QrcodeScanner {
CameraPermissions.hasPermissions().then(
(hasPermissions: boolean) => {
if (hasPermissions) {
+ if ($this.isCleared) {
+ return;
+ }
// Start feed.
// Assuming at this point the permission button exists.
let permissionButton = document.getElementById(