Fix: Add early exit if SCANNER_CONFIG not defined

Prevents potential JavaScript errors if script is loaded
outside the scanner page context.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Eduard Wisch 2026-02-17 11:18:29 +01:00
parent cf244aac31
commit 74b452b82e

View file

@ -7,7 +7,18 @@
'use strict';
// Use SCANNER_CONFIG from page (Dolibarr integrated)
const CONFIG = window.SCANNER_CONFIG || {};
// Exit early if not on scanner page
if (typeof window.SCANNER_CONFIG === 'undefined') {
return;
}
const CONFIG = window.SCANNER_CONFIG;
// Validate required config
if (!CONFIG.ajaxUrl || !CONFIG.token) {
console.error('HandyBarcodeScanner: Invalid configuration');
return;
}
// State
let currentMode = CONFIG.mode || 'order';
@ -33,7 +44,7 @@
};
if (!elements.startBtn || !elements.videoContainer) {
console.error('Scanner elements not found');
// Not on scanner page - exit silently
return;
}