This commit is contained in:
@@ -46,6 +46,52 @@ window.taxbaikAdminSession = {
|
||||
|
||||
window.taxbaikAdminSession.postClientLog = postLog;
|
||||
|
||||
if (!window._taxbaikConsoleErrorPatched) {
|
||||
window._taxbaikConsoleErrorPatched = true;
|
||||
const originalConsoleError = console.error.bind(console);
|
||||
console.error = function (...args) {
|
||||
try {
|
||||
const text = args.map(arg => {
|
||||
if (arg instanceof Error) {
|
||||
return `${arg.message}\n${arg.stack || ''}`;
|
||||
}
|
||||
if (typeof arg === 'string') return arg;
|
||||
try {
|
||||
return JSON.stringify(arg);
|
||||
} catch {
|
||||
return String(arg);
|
||||
}
|
||||
}).join(' ');
|
||||
|
||||
if (text && !text.includes('taxbaikAdminSession.postClientLog') && !text.includes('client-logs')) {
|
||||
postLog({
|
||||
level: 'error',
|
||||
source: 'console.error',
|
||||
message: text.slice(0, 1000),
|
||||
url: window.location.href,
|
||||
route: window.location.pathname + window.location.search,
|
||||
screen: window.taxbaikAdminSession.clientLogState.screen || '',
|
||||
feature: window.taxbaikAdminSession.clientLogState.feature || '',
|
||||
action: window.taxbaikAdminSession.clientLogState.action || '',
|
||||
step: window.taxbaikAdminSession.clientLogState.step || '',
|
||||
entity: window.taxbaikAdminSession.clientLogState.entity || '',
|
||||
entityId: window.taxbaikAdminSession.clientLogState.entityId || '',
|
||||
dataKey: window.taxbaikAdminSession.clientLogState.dataKey || '',
|
||||
buildVersion: window.taxbaikAdminBuildVersion || '',
|
||||
component: window.taxbaikAdminComponent || '',
|
||||
viewportWidth: window.taxbaikAdminSession.getViewportWidth(),
|
||||
userAgent: navigator.userAgent || '',
|
||||
stack: args.find(arg => arg instanceof Error)?.stack || ''
|
||||
});
|
||||
}
|
||||
} catch {
|
||||
// Logging must never break the UI.
|
||||
}
|
||||
|
||||
return originalConsoleError(...args);
|
||||
};
|
||||
}
|
||||
|
||||
window.addEventListener('error', function (event) {
|
||||
postLog({
|
||||
level: 'error',
|
||||
@@ -90,6 +136,12 @@ window.taxbaikAdminSession = {
|
||||
stack: reason?.stack || ''
|
||||
});
|
||||
});
|
||||
|
||||
window.addEventListener('load', function () {
|
||||
window.taxbaikAdminSession.traceUiState('startup', 'window.load');
|
||||
}, { once: true });
|
||||
|
||||
window.taxbaikAdminSession.traceUiState('startup', 'initErrorLogging attached');
|
||||
},
|
||||
|
||||
setContext: function (screen, feature, action, step, entity, entityId, dataKey) {
|
||||
|
||||
Reference in New Issue
Block a user