---
id: api/commands/debug
title: cy.debug()
description: Set a debugger in Cypress and log what the previous command yields.
section: api
source_path: docs/api/commands/debug.mdx
version: 1934fa485ad0afcbbd3bdb674d5c5f1f991b55cf
updated_at: '2026-11-14T05:15:51.878Z'
---
# debug

Set a `debugger` and log what the previous command yields.

You need to have your Developer Tools open for `.debug()` to hit the breakpoint.

## Syntax

```
.debug()
.debug(options)

// ---or---

cy.debug()
cy.debug(options)
```

### Usage

**Correct Usage**

```
cy.debug().getCookie('app') // Pause to debug at beginning of commands
cy.get('nav').debug() // Debug the `get` command's yield
```

### Arguments

**options _(Object)_**

Pass in an options object to change the default behavior of `.debug()`.

| Option | Default | Description |
| --- | --- | --- |
| `log` | `true` | Displays the command in the [Command log](/llm/markdown/app/core-concepts/open-mode.md#Command-Log) |

### Yields

*   `.debug()` yields the same subject it was given from the previous command.
*   `.debug()` is a query, and it is _safe_ to chain further commands.

## Examples

### Debug

#### Pause with debugger after `.get()`

```
cy.get('a').debug().should('have.attr', 'href')
```

#### Confirm the element before acting on it

Place `.debug()` before an action to check which element the action receives.

```
cy.get('form').find('input[name="email"]').debug().type('user@example.com')
```

#### Inspect a subject that isn't a DOM element

`.debug()` works on any subject, such as a response object or the data your application saves in the browser.

```
cy.request('/api/users').debug() // inspect the full response object
cy.getAllLocalStorage().debug() // inspect localStorage for every origin
```

### Network requests

#### Inspect an intercepted request

After [`cy.wait()`](/llm/markdown/api/commands/wait.md) on an alias, the subject is the interception, so you can expand `subject.request.body` and `subject.response` at the breakpoint.

```
cy.intercept('POST', '/api/login').as('login')
cy.get('form').submit()
cy.wait('@login').debug()
```

### Assertions

#### See the first-run subject while an assertion retries

The "Debug Info" block shows the subject from the first time `.debug()` runs. Here, it may log fewer than three items even though `.should()` passes once the list finishes rendering. See [`.debug()` pauses once per call](#debug-pauses-once-per-call).

```
cy.get('.todo-item').debug().should('have.length', 3)
```

The Command Log shows the assertion passing with three items:

The "Debug Info" block, logged on the first run, shows the subject before the list finished rendering:

### Debugger statement

#### Pause with your test's variables in scope

`.debug()` gives you `subject` at the breakpoint. To also reach variables from your test, put a `debugger` statement inside [`.then()`](/llm/markdown/api/commands/then.md). A `debugger` written directly in the test body pauses before any Cypress commands run. The [Debugging guide](/llm/markdown/app/guides/debugging.md) explains why.

The breakpoint only sees a test variable that the `.then()` callback uses. The browser leaves out outer variables the callback never references, so reference each one you want to inspect.

```
const expected = 'Welcome back'

cy.get('h1').then(($h1) => {
  const matches = $h1.text() === expected

  debugger // $h1, expected, and matches are in scope here
})
```

## Notes

### What `.debug()` logs to the console

When `.debug()` runs, it prints a "Debug Info" block to the browser console with the previous command's name, its arguments, and the current subject. When you call `cy.debug()` off of `cy` as the first command in a test, there is no previous command or subject, so each value logs as `undefined`.

### Inspect the subject at the breakpoint

When the `debugger` statement pauses execution, the current subject is in scope as the variable `subject`. Type `subject` in the Developer Tools console to interact with it.

The breakpoint is in Cypress's own `cypress_runner.js`, not in your test file. Look for the "HOVER OVER TO INSPECT THE CURRENT SUBJECT" comment above the paused line, and for `subject` under "Local" in the "Scope" pane:

### `.debug()` pauses once per call

`.debug()` is a query, so Cypress retries it along with the queries before it while any chained assertions are failing. It only logs and hits the breakpoint the first time it runs. The "Debug Info" block shows the subject from that first run, which may differ from the subject Cypress yields once the assertions pass.

## Rules

### Requirements

*   `.debug()` can be chained off of `cy` or off another command.

### Assertions

*   `.debug()` does not run assertions. Assertions pass through as if this command did not exist.

### Timeouts

*   `.debug()` cannot time out.

## Command Log

**_Log out the current subject for debugging_**

```
cy.get('.ls-btn').click({ force: true }).debug()
```

The commands above display in the Command Log as:

When `.debug()` runs, the console outputs the following:

## History

| Version | Changes |
| --- | --- |
| [12.0.0](/llm/markdown/app/references/changelog.md#12-0-0) | `.debug()` became a query and can no longer be overwritten with `Cypress.Commands.overwrite()`. See the [migration guide](/llm/markdown/app/references/migration-guide.md#CypressCommandsoverwrite). |

## See also

*   [Debugging](/llm/markdown/app/guides/debugging.md)
*   [`.pause()`](/llm/markdown/api/commands/pause.md)
*   [`cy.log()`](/llm/markdown/api/commands/log.md)
*   [`cy.screenshot()`](/llm/markdown/api/commands/screenshot.md)
