The Errors That Never Reach Your Server Can Still Be Reported to You. One Header, in Chrome Only.
A visitor says your site would not load. You look at the logs for that minute and there is nothing: no request, no error, no 5xx. That is not a sign the report is wrong. It is what most network failures look like from th
A visitor says your site would not load. You look at the logs for that minute and there is nothing: no request, no error, no 5xx. That is not a sign the report is wrong. It is what most network failures look like from the server, because the request never arrived.
DNS that could not resolve the name, a TCP connection that timed out, a TLS handshake that broke, a connection reset halfway: all of those fail before your code runs. Your access log records requests, and there was no request. Your error tracker runs in the page, and there was no page.
There is a mechanism built for exactly this gap, it has shipped in Chrome since version 71, and almost nobody turns it on.
Network Error Logging
The W3C's Network Error Logging spec lets a site ask the browser to remember a policy and, later, report network failures for that origin to an endpoint you choose. The spec's own example is two response headers:
Report-To: {"group": "network-errors", "max_age": 2592000, "endpoints": [{"url": "https://example.com/upload-reports"}]}
NEL: {"report_to": "network-errors", "max_age": 2592000}
The first names an endpoint group. The second tells the browser to report network errors for this origin to that group, for 2,592,000 seconds, thirty days.
When a later request to your site fails, the browser queues a report and sends it when it can. The failure types are named in the spec, and they are exactly the ones you never see:
-
dns.name_not_resolved: "DNS server responded but is unable to resolve the address" -
tcp.timed_out,tcp.refused,tcp.reset,tcp.aborted - TLS failures during secure connection establishment, and HTTP errors in transmission
So the visitor whose page never loaded produces a record after all, just not in the log you were looking at.
The three conditions that decide whether you get anything
The browser has to have seen your policy first. It arrives in a response header, so a visitor who has never once loaded your site successfully has no policy and sends nothing. And the spec says registration "will only succeed if the response is communicated from a potentially trustworthy origin", which in practice means HTTPS.
The report has to have somewhere to go. If your endpoint lives on the same servers that just failed, the report fails with them, so put the endpoint on separate infrastructure from the site it is watching.
It is Chromium only. MDN's compatibility data lists Chrome from 71 and Edge from 79, and no support in Firefox or Safari. What you collect is a picture of your Chromium users only, so a failure that hits Firefox or Safari visitors stays as invisible as before.
A privacy rule that changes what a DNS report means
The spec includes a deliberate downgrade. If the server's IP address on a failing request does not match the one the policy was received from, the browser rewrites the report: the phase becomes dns, the type becomes dns.address_changed, and the status code and timing are cleared. The spec's note explains why: it ensures "NEL reports are only sent to the owner of the service that the report describes."
Read that the other way round and it is a diagnostic. A spike of dns.address_changed reports means visitors are being sent to an address you did not serve them from: a stale DNS record, a misconfigured resolver, or something worse sitting in the path.
The spec also has an example worth copying. With "include_subdomains": true, the owner of example.com hears about a request to new-subdomain.example.com that fails to resolve, which is how you find out you created the link before you created the DNS record.
What it costs, and what it buys
Two headers and an endpoint that accepts JSON. In return, the reports that used to read "your site is down" and matched nothing in your logs now have a counterpart: a time, a URL, a failure type and a phase, from the browser that failed.
It will not tell you which network the visitor was on or what they did next. But it turns "we cannot reproduce it and there is nothing in the logs" from a dead end into a question with data behind it.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.