Skip to content

Report errors from another frame as themselves, and leave out Cloudflare's own - #2926

Merged
davidmckayv merged 1 commit into
mainfrom
fix/cross-realm-error-reporting
Dec 4, 2026
Merged

davidmckayv merged 1 commit into
mainfrom
fix/cross-realm-error-reporting

Conversation

@davidmckayv

@davidmckayv davidmckayv commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

What and why

On OpenBot Cloud, nearly every page load sent an error report reading "A object was thrown": 575 of them since 22:10Z on 3 December. They hid real errors.

The cause, read live from OpenBot Cloud's sign-in page in Chrome and in WebKit:

  • Cloudflare's JavaScript detections write a script into every page. It makes a hidden 1x1 frame on the page's own address and writes its loader (/cdn-cgi/challenge-platform/scripts/jsd/main.js) into it with innerHTML.
  • The frame keeps the page's Trusted Types rule (index.html) but none of OpenBot's policies (app/src/lib/trusted-types.ts). So the browser refuses the write, and the refusal reaches the window as an uncaught error. Chrome words it TypeError: This document requires 'TrustedHTML' assignment. at HTMLDocument.c (https://my.open.bot/sign:291:154), and WebKit as TypeError: This assignment requires a TrustedHTML, c@https://my.open.bot/sign:291:145.
  • That error object was made in the frame, so it isn't instanceof this window's Error. The reporter (app/src/lib/error-reporting.tsx) only knew this window's Error, so it sent the placeholder.

The fix

  • Errors from another frame are recognised. The check now goes in this order: the browser's own Error.isError where it has one, then the built-in tag ([object Error], [object DOMException], [object Exception], [object DOMError], [object WebAssembly.Exception]), then instanceof. That way an error from any same-origin frame is reported with its real name, message and stack.
  • Cloudflare's own errors are left out. Two narrow rules:
    • an error thrown in a file under /cdn-cgi/, judged by where the browser says it was thrown, or else by the top line of its stack;
    • Cloudflare's refusal itself. It is dropped only when all of these hold: it is a Trusted Types refusal, it was made in another frame, every line of its stack is in the page's own markup (not one of OpenBot's files), and the page carries Cloudflare's /cdn-cgi/challenge-platform/ loader.
  • OpenBot's own Trusted Types refusals are thrown from its own files, whether in its window or in a frame of its own, so they are still reported.
  • Trusted Types and the CSP are unchanged, and nothing changes in Cloudflare.

How the leaders do it

  • Recognising errors from another realm: most of them check the built-in tag first and instanceof second.
    • Sentry's isError switches on Object.prototype.toString (Error, Exception, DOMException, WebAssembly.Exception) and only then uses instanceof Error (sentry-javascript is.ts).
    • PostHog's SDK uses the same switch, with DOMError added (posthog-js type-utils.ts).
    • Bugsnag uses the iserror package, the same check (bugsnag-js iserror.js).
    • Datadog RUM checks instanceof Error || toString === '[object Error]' (browser-sdk isError.ts).
    • We follow the majority. We also try the native Error.isError first where the browser has it. It answers the same question, and only adds a check.
  • Third-party and injected-script noise:
    • Sentry drops errors by the script URL in the stack frame (denyUrls), and its thirdPartyErrorFilterIntegration drops errors whose frames aren't in the app's own files (Sentry filtering docs).
    • Datadog drops them in beforeSend (Datadog: enrich and control RUM data).
    • PostHog uses suppression rules on the exception's type and message (PostHog: reduce noise).
    • Bugsnag ignores cross-domain script errors by default, because they carry nothing to act on, and the app drops others in its onError callback (Bugsnag browser FAQ).
    • This change follows Sentry's two rules: drop by the file's URL under /cdn-cgi/, and drop an error whose whole stack is outside OpenBot's files. It narrows the second rule to Cloudflare's Trusted Types refusal, so nothing of OpenBot's is dropped with it.

Tests

app/tests/app-error-reporting-browser.test.ts is a real-browser test in Chromium and WebKit, with the app's own Trusted Types <meta> and Cloudflare's script as OpenBot Cloud's page carries it. It is added to the app (real browser, WebKit) list, which runs both engines.

  1. An error made in a same-origin frame, thrown at the window and rejected with nobody handling it, is reported with its real name, message and stack.
  2. Cloudflare's Trusted Types refusal and an error from a script under /cdn-cgi/ are not reported.
  3. OpenBot's own Trusted Types refusals on that same page are still reported, both in its window (TrustedScript) and in a frame of its own (TrustedHTML, a refusal made in another frame like Cloudflare's).

All four tests (each of the three cases above, in both engines) fail without the fix and pass with it:

without the fix: 0 pass, 4 fail
  chromium/webkit frame: sent [{"type":"Error","message":"A object was thrown"}]
  chromium/webkit cloudflare: Cloudflare's errors were sent
with the fix:    4 pass, 0 fail

app/tests/app-error-reporting.test.tsx also checks how a stack's addresses are read, against the exact Chrome and WebKit stacks taken from OpenBot Cloud.

Changelog

Web app.

  • Error reports from the web app name errors from another frame properly, and leave out Cloudflare's own script errors on OpenBot Cloud.

…are's own

OpenBot Cloud's Cloudflare zone injects a script into every page that makes a
hidden same-origin frame and writes its loader into it with innerHTML. The
frame inherits the page's Trusted Types rule but not OpenBot's policies, so
Chrome and Safari refuse the write, and the refusal reaches the window as an
uncaught error made in the frame. It isn't instanceof this window's Error, so
the reporter sent "A object was thrown": 575 junk reports since 3 December,
nearly one per page load, hiding real errors.

- An error is recognised whichever frame made it: Error.isError where the
  browser has it, then its built-in tag ([object Error], DOMException and the
  like), then instanceof, as Sentry, PostHog's SDK and Bugsnag do. Its real
  name, message and stack are sent.
- Cloudflare's own errors are left out, as Sentry's denyUrls and third-party
  filter do: one thrown in a file under /cdn-cgi/, and the Trusted Types
  refusal made in another frame whose whole stack is in the page's own markup,
  on a page that carries Cloudflare's loader. OpenBot's own Trusted Types
  refusals, thrown from its files in its window or a frame of its own, are
  still reported. Trusted Types and the CSP are unchanged.

A real-browser test in Chromium and WebKit holds all three, against
Cloudflare's script as OpenBot Cloud's page carries it.
@davidmckayv
davidmckayv added this pull request to the merge queue Dec 4, 2026
Merged via the queue into main with commit ab684e5 Dec 4, 2026
76 of 78 checks passed
@davidmckayv
davidmckayv deleted the fix/cross-realm-error-reporting branch December 4, 2026 07:46
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