## TL;DR

Cypress fails the test when the app throws. The right fix is usually in the app, but for known third-party noise you can ignore specific exceptions with `Cypress.on('uncaught:exception')` returning false, scoped as narrowly as possible.

## Error

```text
CypressError: `cy.visit()` failed because an uncaught exception was thrown by the application:
TypeError: Cannot read properties of null (reading 'track')
```

## Steps

1. Read the exception: is it your app's code or a third-party script (analytics, chat widget)? Expected: you know who owns the bug.
2. If it is your app, fix it; a throwing app is a real bug the test correctly caught. Expected: the exception disappears and the test passes honestly.
3. If it is third-party noise you cannot fix, ignore it narrowly in `cypress/support/e2e.js`: `Cypress.on('uncaught:exception', (err) => { if (err.message.includes('track')) return false })`. Expected: only that message is ignored.
4. Never `return false` unconditionally; it blinds the suite to real app crashes. Expected: the handler names the exact messages it swallows.
5. Re-run and confirm the test passes AND that a deliberately introduced app error still fails a test. Expected: the ignore is proven narrow.

## When to use

- The stack trace points into application or vendor scripts.
- A third-party script throws on every page load.

## When not to use

- The error is in your spec or support files (fix the test code).
- You are tempted to ignore all exceptions to make the suite green (that deletes the suite's value).

## Tool compatibility

- Cypress 10 through 14; handler registered in the support file.

## Variant phrasings

### Cypress failed the test because the application threw

Same event; decide app fix vs narrow ignore.

### Uncaught TypeError from the application under test

Read whose TypeError it is before choosing.

## Why it happens

Cypress listens for page errors because an app that throws is usually broken. It fails fast rather than letting assertions run against a crashed page.

## Edge cases

- Errors thrown inside `cy.origin()` callbacks surface differently; handle them in the origin callback.
- Source-mapped stacks help only if the app serves sourcemaps in the test env.
- Flaky third-party scripts make the ignore list grow; prefer stubbing the vendor script with an intercept.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_ZoMnx3DmSsvPr3nauEKS9Q
