All posts
Liferay · 12 min read · Jul 5, 2026

Capturing Frontend Errors in a Portal Without a Third-Party Service

Client-side error capture stored inside the portal

A user reports that a page did not work. The server log shows a clean request with a 200 response, nobody can reproduce it, and the ticket is closed as not reproducible. Two weeks later it happens again. This is the normal state of affairs for browser-side failures, because the only place the evidence existed was a console nobody was watching.

Opening developer tools is how you investigate a failure you can reproduce. That is a different skill and a different situation from the one here: capturing failures that happen on other people's machines, at times you are not present, in a portal where you may never get a reproduction at all.

Why not a hosted service

The obvious answer is a commercial monitoring service, and for many products that is the right call. Enterprise portals frequently rule it out for reasons that have nothing to do with engineering preference.

  • The portal is on an internal network with no route to an external endpoint.
  • Data residency rules forbid sending anything, including a stack trace, outside the organisation.
  • The content security policy does not allow a third-party script, and widening it needs its own approval.
  • Procurement for a new vendor takes longer than the project has.
  • URLs and payloads in this domain routinely contain data that must not leave the estate.

When any of these apply, the choice is not between building and buying. It is between building and having nothing, and nothing is what most portals run with.

What is worth capturing

Four sources cover nearly every browser-side failure, and they need separate handlers because none of them catches the others.

javascript
// 1. Uncaught exceptions
window.addEventListener('error', (event) => {
    if (event.target !== window) {
        // 2. Failed resource loads bubble here with a target
        return record('resource', { url: event.target.src || event.target.href });
    }
    record('error', {
        message: event.message,
        source: event.filename,
        line: event.lineno,
        stack: event.error && event.error.stack,
    });
}, true);

// 3. Promise rejections never reach the error handler
window.addEventListener('unhandledrejection', (event) => {
    record('rejection', { message: String(event.reason) });
});

// 4. Failed API calls, which are not exceptions at all
const nativeFetch = window.fetch;
window.fetch = async function (...args) {
    const response = await nativeFetch.apply(this, args);
    if (!response.ok) {
        record('http', { url: response.url, status: response.status });
    }
    return response;
};
Four handlers, because an unhandled rejection and a 500 response are invisible to the error event.

The fourth is the one most often skipped and the most valuable in a portal. A failed API call does not throw, so it produces no error at all - the screen simply stays empty, which is precisely the failure users describe as it did not work.

Context is what makes a report usable

A stack trace alone rarely identifies anything. What turns a record into something actionable is the surrounding context, and the useful set is short.

CaptureWhy
Page URL, with the query string strippedLocates the failure without dragging in parameters
The widget or fragment on the pageA portal page has many owners; this names one
A release or build identifierDistinguishes a regression from a long-standing bug
A session-scoped correlation idLinks several errors from one user journey
Browser and viewportMost unreproducible bugs are one browser or one width
Timestamp in UTCCorrelates with server logs, which is where the other half is
Enough to investigate, and deliberately nothing more.

What not to capture matters equally. Form values, anything from local storage, full query strings, and free-text content should never enter the record. The rule that keeps this honest is that the error store must be safe to expose to any developer on the team, because that is exactly who will be reading it.

Storing it inside the portal

The natural home is an object definition, because it arrives with the things a log file does not have: a REST API to write to, permissions so only the right roles can read it, an administrative screen for free, and a schema that makes the records queryable. Treating monitoring data as just another structured entity removes almost all of the infrastructure work from the project.

Retention needs deciding on day one rather than discovered later. Error records accumulate faster than any other data in the system, and a scheduled job that deletes anything older than a chosen window is a five-line addition that prevents a table nobody can query a year later.

Volume is the real engineering problem

A naive implementation that posts every error will, on its first bad day, generate more traffic than the application it monitors. A single error inside a scroll handler produces thousands of identical records in a minute.

  1. Fingerprint each error - message plus the top stack frame - and send one record per fingerprint per page view, with a count.
  2. Cap the total records per page view, and stop silently once the cap is hit.
  3. Batch records and send them together rather than one request per error.
  4. Send the final batch with sendBeacon on page hide, so errors just before navigation are not lost.
  5. Sample aggressively on high-traffic pages; you need the fingerprint, not every instance.

The counting matters as much as the deduplication. One record saying this happened four hundred times is useful; four hundred records is a denial of service you wrote yourself.

Filtering the noise you did not cause

A large share of what lands in a production error handler has nothing to do with your code. Browser extensions inject scripts, translation tools rewrite the DOM, and corporate security agents wrap network calls. These produce errors in your handler, from files you did not ship.

Two filters remove most of it: ignore errors whose source file is not served from your own origin, and ignore the well-known opaque message that cross-origin scripts produce with no usable detail. Without these, the top entries in your error list will permanently be things you cannot fix, which is how teams learn to ignore the tool they just built.

Never let the monitor break the page

The capture layer runs on every page, inside error paths, when things are already going wrong. It must be incapable of making anything worse.

javascript
function record(type, data) {
    try {
        if (queue.length >= MAX_PER_PAGE) return;
        queue.push({ type, ...data, at: new Date().toISOString() });
    } catch (e) {
        // Monitoring must never throw into the page it monitors.
    }
}
Every entry point wrapped, every failure swallowed - the one place where silent catch is correct.

The same applies to the transport. If the endpoint that receives errors is itself failing, the capture layer must not retry into a loop, and its own failed request must not be recorded as an error.

Using what you collect

Collection without a workflow becomes a table nobody opens. The practice that keeps it alive is to alert on new fingerprints rather than on volume. A new fingerprint appearing after a release is a regression with a known cause and a known window - which is the single highest-value signal the whole system produces.

Grouping by page and by widget turns the data into something a team can act on, because it tells you who owns the fix. In a portal where several teams contribute to the same page, that attribution is often the hardest part of the investigation, and this is the only place it exists.

Conclusion

Building your own frontend monitoring is a weekend of code and a week of judgement. Capture the four sources, attach just enough context to investigate, store it as structured data inside the portal where permissions and retention already exist, and spend most of your effort on deduplication, capping and noise filtering. Get that right and the vague unreproducible ticket stops being the end of the investigation and becomes the start of one.

Contact

Let’s connect

Have a Liferay or Backend project you’d like to talk through? Fill in the form and I’ll get back to you.

Book Calendar