AlgoViz

Monitoring client-side errors

medium 32 min

Some errors never reach your servers: a name that does not resolve, a blocked connection, a script that breaks in the browser.

Video lesson · Chapter 1 of 6

Observe a failed interaction

0:00 / 4:03

Theory

Read or listen first. About 2 min.

What it is

Client-side errors happen on the user's device or on the way to you: in the browser, in the app, in the network, in the name system. Your servers do not see them, because no request arrives or because the request was fine.

Client-side monitoring lets the browser tell you. A small script catches errors, notes what happened before, measures how fast the page felt, and sends this to a collector.

Why it exists

Server charts can be perfectly green while nobody can use the site. A wrong DNS entry makes traffic fall, and zero requests have zero errors.

Much of a web page runs in the browser, in thousands of combinations of device, browser, network and extension. A fault in one of them cannot be found on your own machine.

And users rarely write. If a button does nothing, most of them leave.

A short history

  1. September 2017

    React 16 brings error boundaries. An error that none of them catches removes the whole tree from the page.

  2. March 2024

    Interaction to Next Paint (INP) replaces First Input Delay (FID) among Google's Core Web Vitals.

  3. December 2024

    Ecma publishes ECMA-426, a standard for the source map format.

  4. May 2025

    Version 5 of the web-vitals library removes the function for FID. The W3C publishes a new working draft of Network Error Logging.

Words to know

RUM
Real User Monitoring: data from real visitors in production.
Synthetic check
A robot that uses the site on a schedule.
Breadcrumbs
The last actions before an error.
Source map
A file that translates positions in minified code to your own lines.
Error boundary
A React component that catches errors while its children are drawn.
NEL
Network Error Logging: the browser reports failed connections by itself.
Beacon
A small message the browser sends even when the page closes.
Core Web Vitals
LCP for loading, INP for reacting, CLS for calm layout.
Session replay
A reconstruction of what a user saw, made of page changes.

Understand it

Start here

The stuck garden gate

Letters that never reached the kitchen
0complaints

A complaint box in the kitchen cannot tell you that nobody can get in.

In the gardenIn the system
KitchenYour servers
Stuck gateDNS, certificate, network
Box outsideCollector on another domain
LetterError report
TesterSynthetic check
FootprintsBreadcrumbs

The idea

Two points of view

Only the client sees

  • What the user really experienced.
  • The speed on this device.
  • Delay of this place and network.
  • Actions before the error.
  • Broken layout.

The server cannot see

  • Errors of scripts in the browser.
  • Browsers that behave differently.
  • Slow drawing, a frozen page.
  • Network faults of the user.
  • Scripts of other companies.

Three groups of faults

  • Cannot reach

    DNS, certificate, blocked network, dead CDN. No request arrives.

  • Arrives, breaks

    A script error, a missing file, an API that answers unexpectedly.

  • Works, too slow

    Loading, reacting, jumping layout.

A collector with a life of its own

A browser uses our site through a CDN and an API. It sends reports to a collector in a different network. The collector feeds an error tracker, which informs the person on call.
Blue: the site. Orange dashed: reports, on another domain, network and provider.

Group 1

When nobody reaches you

FaultThe user seesYour servers see
DNS failureSite not foundLess traffic
Certificate expiredA warning pageFailed handshakes at the edge, no requests
Network path brokenTimeoutLess traffic from one region
CDN or edge downError page of the CDNNothing
OfflineNothing worksNothing
CORS refusedA function does nothingOften a normal request, sometimes only a preflight

Traffic fell. Whose problem?

Three nets catch this group. Browsers report it themselves (NEL). Probes in several networks try the site every minute. And an alert on missing traffic compares with the same hour last week.

HTTP
Report-To: {"group": "net", "max_age": 2592000,  "endpoints": [{"url": "https://collect.example.net/nel"}]}NEL: {"report_to": "net", "max_age": 2592000,  "success_fraction": 0.001, "failure_fraction": 1.0}
Network Error Logging. The site tells the browser where to report. The collector is on another domain.

The browser remembers this for max_age seconds, here 30 days, and reports for example dns.name_not_resolved later, when it has a connection. Two limits: a person who never reached you has no policy yet, and not every browser supports it. It is a working draft.

Names and their failures are explained in DNS, the edge in CDN operations.

Group 2

When the page breaks

ErrorExampleUsual cause
TypeErrorCannot read properties of undefinedMissing data
ReferenceErrorfoo is not definedScript not loaded, name wrong
SyntaxErrorUnexpected tokenOld browser, or HTML instead of a script
RangeErrorMaximum call stack size exceededEndless recursion
ChunkLoadErrorLoading chunk 5 failedAn outdated page: its files are gone after a release
ResourceImage, script or style missingBlocker, CDN, wrong address
API4xx or 5xx, timeoutSee the server's errors

Where to catch them

PlaceCatchesMind
window error eventErrors nobody caughtScripts of other origins give only Script error without CORS
unhandledrejectionPromises nobody handledAsync code needs this one
try and catchCode you expect to failReport it, do not swallow it
Error event with captureImages, scripts, styles that did not loadThese events do not bubble, so listen in the capture phase
React error boundaryErrors while drawingNot event handlers, not async code
For scripts from another origin add the crossorigin attribute and a CORS header to see their details.
Text
14:32:01 navigation  /checkout14:32:03 click       Add to cart14:32:04 request     POST /api/cart     20014:32:06 click       Checkout14:32:07 request     POST /api/payment  50014:32:07 error       TypeError: Cannot read properties                     of undefined (reading 'card')
Breadcrumbs: the trail before an error.

Here the trail tells the story: the server answered 500, and the page read a card from an answer that was not there. Two faults: the server's, and a page that did not expect it.

From a click to an issue

Send

Getting the report out

WayGoodLimit
sendBeaconSent in the background, also when the page closes64 KiB in the queue, no answer
fetch with keepaliveOwn headers, also when the page closesAlso limited in size
Kept on the deviceOfflineSent at the next visit, if there is one
MDN advises to send at visibilitychange to hidden. The unload event is not reliable.

Limit the number of reports per page, for example ten. A fault in a loop would otherwise send thousands. Group on the device: the same stack again raises a counter instead of sending.

How much arrives

10,000,000×1%×2 KB=200 MB per day10{,}000{,}000 \times 1\% \times 2\,\text{KB} = 200\,\text{MB per day}
Ten million page views, one report in a hundred views, 2 KB each. A bad release with ten reports in every view would be 200 GB. Hence the limits.

The collector is public, so anybody can send nonsense. Limit by address, check the shape, cut long fields, and never trust a field when showing it on an internal page.

Translate

Source maps

Scripts are sent minified. A stack says app.5abc.js:1:48213. The source map of that release says checkout.ts, line 45, function pay. Upload the map to the tracker when you build, with the release name.

A page that is older than your server

StepWhat happens
9:00A visitor opens the page. It knows the file 5.abc.js
9:30You release. The file is now 5.def.js, the old one is deleted
9:40The visitor opens a new part: loading chunk 5 failed
Keep old files for some days. And when a chunk fails, reload the page once. Do not filter these errors away: count them.

Protect

Error boundaries

In React an error while drawing removes the whole page, unless an error boundary catches it. Put one around each independent part: a broken chart then shows a small message and the rest goes on.

A boundary does not catch errors in event handlers, in async code, on the server, or in itself. React 19 also has root options such as onUncaughtError to report what no boundary caught.

Who catches this error?

Own try and catch comes before all of these.

Group 3

How it feels: Core Web Vitals

VitalQuestionGoodNeeds workPoor
LCPWhen is the main content there?up to 2.5 sup to 4 sover 4 s
INPHow fast does it react?up to 200 msup to 500 msover 500 ms
CLSDoes the layout jump?up to 0.1up to 0.25over 0.25
Judge the 75th percentile, for mobile and desktop apart. INP replaced FID in March 2024.
Also usefulMeaningGood
TTFBFirst byte arrivesup to 0.8 s
FCPFirst content drawnup to 1.8 s
Time to Interactive was removed from Lighthouse with version 10.

Google says that its ranking systems use Core Web Vitals, and that good values alone do not guarantee a good rank. The better reason is the visitor. How to make things faster is in latency.

Real or robot

RUM and synthetic checks

RUM

  • Real devices, networks and places.
  • All browser versions.
  • Shows how many are affected.
  • Silent when nobody can come in.

Synthetic

  • Robots from fixed places.
  • Equal conditions, good for comparing.
  • Works at night and before a launch.
  • Tests only the paths you wrote.
RUM collectsExamples
SpeedLoad time, LCP, INP, resource times, long tasks
ErrorsExceptions, failed requests, missing files, console errors
ContextBrowser, device, country, session, actions

Do not average, take the 75th percentile

P75 of (1,1,2,9)=2 s,mean=3.25 s\text{P75 of } (1, 1, 2, 9) = 2\,\text{s},\quad \text{mean} = 3.25\,\text{s}
Three of four visits took at most 2 s. The mean describes none of them.

See

Session replay

  1. 1

    Take the page

    The structure of the page at the start.

  2. 2

    Note changes

    Each later change of the structure.

  3. 3

    Note events

    Mouse, scrolling, keys, without the typed text.

  4. 4

    Rebuild

    Play it in a closed frame. It is not a video, so it is much smaller than one.

An example: page load, scroll, click on a form, type an e-mail, click on send, error. You see at once that the button was hidden behind a banner.

Who is recorded

SessionsShareWhy
All10%, for exampleGeneral picture
With an error100%The useful ones
Important customersMoreSupport

Known tools: Sentry for errors and replay, Datadog RUM, LogRocket, Fullstory. All of them receive data about your users, so your contract and your privacy notice must say so.

Decide

How bad is it?

Which reaction?

Count affected sessions, not events. One broken tab can send a hundred events.

Summary

The whole topic in one minute.

Errors outside your servers come in three groups: nobody reaches you, the page breaks, or it is too slow. The first needs browser reports, probes from outside and an alert on missing traffic. The second needs handlers, breadcrumbs and source maps. The third needs measurements from real users.

The collector must not share the fate of the site: another domain, network and provider. Send little, hide personal data on the device, and count users, not events.

  • Zero requests have zero errors: alert on missing traffic.
  • The collector shares nothing with the site.
  • Catch errors, promises, resources and drawing.
  • Breadcrumbs, release, source map.
  • LCP, INP, CLS at the 75th percentile of real users.
  • Mask on the device, limit reports, count sessions.

Sources