Common Front-End Error Types and Their Capture Methods

Front‑end monitoring must capture JavaScript runtime errors, resource loading failures, unhandled promise rejections, and asynchronous request issues using window.onerror, error event listeners, unhandledrejection handlers, and fetch/XHR wrappers, while also handling framework‑specific hooks and cross‑origin script restrictions through CORS or manual try‑catch reporting.

vivo Internet Technology
vivo Internet Technology
vivo Internet Technology
Common Front-End Error Types and Their Capture Methods

As front‑end pages carry more functions, browsers become complex, making it impossible to guarantee error‑free releases even with thorough testing. Therefore front‑end monitoring is essential.

Monitoring typically includes performance, error, and user behavior reporting. This article focuses on error monitoring, describing common error types and how to capture and report them.

Common error categories

1. JavaScript runtime errors – caused by undefined variables, compatibility issues, etc. Example screenshot (omitted).

2. Resource loading errors – failures when loading JS, CSS, images, often via CDN.

3. Unhandled promise rejections – promises rejected without a catch.

4. Asynchronous request errors – errors from fetch or XMLHttpRequest (XHR).

Capture methods

1. window.onerror and window.addEventListener('error') for runtime errors.

window.onerror = function (msg, url, lineNo, columnNo, error) {
    // handle error information
};
// demo
msg: Uncaught TypeError: ReferenceError: a is not defined
error.stack: TypeError: ReferenceError: a is not defined at http://xxxx.js:1:13
window.addEventListener('error', event => {
    // handle error information
}, false); // false = bubble phase, true = capture phase

2. Resource loading errors – listen to the error event on elements like

,

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

frontendJavaScriptWeb Performanceerror-monitoringfetchXHR
vivo Internet Technology
Written by

vivo Internet Technology

Sharing practical vivo Internet technology insights and salon events, plus the latest industry news and hot conferences.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.