Skip to content

Say where an app error happened: the route's pattern, languages, translation and browser - #2935

Open
davidmckayv wants to merge 2 commits into
mainfrom
error-report-browser-context
Open

davidmckayv wants to merge 2 commits into
mainfrom
error-report-browser-context

Conversation

@davidmckayv

Copy link
Copy Markdown
Contributor

What and why

The web app's error reports reach PostHog through OpenBot's own server, so they carry the server's user agent and nothing about the browser. React's NotFoundError: Failed to execute 'insertBefore' on 'Node' (and removeChild) has reached PostHog 8 times since 3 December, from Cloud and from Desktop installs in China, Brazil and Japan, and people land on "This page couldn't be shown". It is almost certainly a page translator rewriting the text React drew, but today's reports can't show that or say which screen it was.

Each report now says where it happened, without saying who or what was on the page. All the new AppError fields are optional:

Field From Example
route the router's deepest match, as its pattern /bots/$botId
pageLanguage <html lang> ja
pageTranslated translated-ltr/translated-rtl on <html>, Google's <font style="vertical-align…"> wrappers, Microsoft's _msttexthash true
browserLanguage navigator.language pt-BR
browserName, browserVersion Bowser, reading the user agent string and the client hints' brands Chrome, 141
osName, osVersion Bowser for the name. The version comes from the client hints' platformVersion where Chromium has them (13 or more is Windows 11). Without hints it is sent only for iOS and Android, because every browser freezes the Windows and macOS versions in its user agent string Windows, 11

Privacy. There are no addresses, query strings, fragments, IDs or page text, only the route's pattern, two language tags, a yes or no, and the browser's and OS's names and major versions. The app holds each value to the pattern the spec gives it and leaves out any value that doesn't fit, so a report is never refused because of them.

Bundle. The user agent parser is Bowser (MIT, about 100M downloads a week, last release November 2026). It loads in its own 7.6 KB gzipped chunk when reporting is installed, so the entry chunk doesn't grow.

How the leaders do it

Two of the three group pages by their route's pattern rather than the raw URL, and all three attach the browser's and OS's names, versions and locale. This change follows them.

Chromium freezes the OS in its user agent string, so the version comes from client hints. Sources: https://developer.chrome.com/docs/privacy-security/user-agent-client-hints and https://learn.microsoft.com/en-us/microsoft-edge/web-platform/how-to-detect-win11

API

The new fields are optional request fields on AppError, which is additive under docs/api-and-migrations.md. oasdiff reports no breaking change, and api:lint passes.

Only the web app sends AppError, and its own server serves it. A server older than this spec refuses unknown fields in this body. So during a rolling upgrade, a page loaded from a newer server that reports to an older one loses that one report. Any new request field has the same window.

Tests

app/tests/app-error-reporting-browser.test.ts runs in Chromium and WebKit. A screen under the app's router throws at /bots/bot_8f3a9c2e?q=private-search#section-2. The page is marked as Google Translate leaves it (<html lang="ja" class="translated-ltr">), and the browser prefers pt-BR.

  • The report carries route: "/bots/$botId", pageLanguage: "ja", pageTranslated: true and browserLanguage: "pt-BR".
  • It names the browser (Chrome or Safari) with its major version, and the OS.
  • Apart from the stack, it holds none of the ID, query, fragment or host.
  • An untranslated page reports pageTranslated: false.

Red/green, locally:

  • With main's reporter: 4 fail and 4 pass. The 4 that fail are the new tests in both engines. The 4 that pass are the existing ones.
  • With the change: 8 of 8 pass.
  • The neighbouring app tests pass: 42 across 6 files.

Changelog

API.

  • Added: an app error report can say where it happened. AppError (recordAppError, recordSignedOutAppError) takes optional route, pageLanguage, pageTranslated, browserLanguage, browserName, browserVersion, osName and osVersion. They hold the route's pattern, never its address, and names and major versions, never a user agent string.

Web app and OpenBot Desktop.

  • Improved: error reports say which screen and browser they came from. Each report the app sends about an error it didn't handle now names the screen by its route's pattern, never its address. It also gives the page's and the browser's languages, whether the browser had translated the page, and the browser and operating system. So errors caused by a translated page can be told apart from bugs.

…slation and browser

Error reports reach PostHog through the server, so they carried the server's user agent and nothing of the browser. React's insertBefore/removeChild NotFoundError, almost certainly from page translators, could not be told apart from a bug or tied to a screen.

AppError gains optional route (the matched route's pattern, never the address), pageLanguage, pageTranslated (Google's and Microsoft's translator marks), browserLanguage, and the browser's and OS's names and major versions (Bowser, with client hints for the OS version where Chromium has them). Each value is held to the spec's pattern and left out when it doesn't fit.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant