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:
parent
cf244aac31
commit
74b452b82e
1 changed files with 13 additions and 2 deletions
|
|
@ -7,7 +7,18 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// Use SCANNER_CONFIG from page (Dolibarr integrated)
|
// 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
|
// State
|
||||||
let currentMode = CONFIG.mode || 'order';
|
let currentMode = CONFIG.mode || 'order';
|
||||||
|
|
@ -33,7 +44,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!elements.startBtn || !elements.videoContainer) {
|
if (!elements.startBtn || !elements.videoContainer) {
|
||||||
console.error('Scanner elements not found');
|
// Not on scanner page - exit silently
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue