| 1 |
const MAX_ERRORS = 24 |
| 2 |
|
| 3 |
window.codeSnippetsErrors = window.codeSnippetsErrors ?? [] |
| 4 |
|
| 5 |
const record = (entry: string): void => { |
| 6 |
if (window.codeSnippetsErrors && window.codeSnippetsErrors.length < MAX_ERRORS) { |
| 7 |
window.codeSnippetsErrors.push(entry) |
| 8 |
} |
| 9 |
} |
| 10 |
|
| 11 |
// Capture phase also delivers failed resource loads, as bare Events carrying none of the |
| 12 |
// detail below. Recording those would fill the buffer with entries naming nothing. |
| 13 |
window.addEventListener('error', event => { |
| 14 |
if (event instanceof ErrorEvent) { |
| 15 |
record(`${event.message || 'Error'} — ${event.filename || 'unknown'}:${event.lineno}`) |
| 16 |
} |
| 17 |
}, true) |
| 18 |
|
| 19 |
window.addEventListener('unhandledrejection', event => { |
| 20 |
const reason: unknown = event.reason |
| 21 |
record(`Unhandled rejection — ${reason instanceof Error ? reason.message : String(reason)}`) |
| 22 |
}) |
| 23 |
|
| 24 |
export {} |
| 25 |
|