Debug: add error overlay + App.init catch
This commit is contained in:
parent
7a27b2cf3f
commit
75b9fc018f
@ -344,3 +344,34 @@ function escapeHtml(s) {
|
|||||||
if (!s) return '';
|
if (!s) return '';
|
||||||
return String(s).replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
return String(s).replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Debug-оверлей: показывает ошибки JS прямо на экране (для отладки в обычном браузере)
|
||||||
|
window.addEventListener('error', (e) => {
|
||||||
|
console.error('Global error:', e);
|
||||||
|
showDebugError(e.message + ' @ ' + (e.filename || '?') + ':' + (e.lineno || '?'));
|
||||||
|
});
|
||||||
|
window.addEventListener('unhandledrejection', (e) => {
|
||||||
|
console.error('Unhandled rejection:', e);
|
||||||
|
showDebugError('Promise: ' + (e.reason && e.reason.message ? e.reason.message : (e.reason || 'unknown')));
|
||||||
|
});
|
||||||
|
function showDebugError(msg) {
|
||||||
|
try {
|
||||||
|
let d = document.getElementById('debug-errors');
|
||||||
|
if (!d) {
|
||||||
|
d = document.createElement('div');
|
||||||
|
d.id = 'debug-errors';
|
||||||
|
d.style.cssText = 'position:fixed;top:0;left:0;right:0;max-height:50vh;overflow:auto;background:#900;color:#fff;padding:12px;font:12px monospace;z-index:99999;white-space:pre-wrap;';
|
||||||
|
document.body.appendChild(d);
|
||||||
|
}
|
||||||
|
const line = document.createElement('div');
|
||||||
|
line.textContent = msg;
|
||||||
|
d.appendChild(line);
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
App.init().catch((e) => {
|
||||||
|
console.error('App.init failed:', e);
|
||||||
|
showDebugError('App.init: ' + (e && e.message ? e.message : String(e)));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user