{
  "doc": {
    "id": "api/commands/window",
    "title": "window | Cypress Documentation",
    "description": "Get the window object of the page that is currently active in Cypress.",
    "section": "api",
    "source_path": "/llm/markdown/api/commands/window.md",
    "version": "fa8f60eba6ec9a949b75fe9f9f5f6591719cd01f",
    "updated_at": "2026-05-05T21:21:10.048Z",
    "headings": [
      {
        "id": "api/commands/window#window",
        "text": "window",
        "level": 1
      },
      {
        "id": "api/commands/window#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/commands/window#usage",
        "text": "Usage",
        "level": 3
      },
      {
        "id": "api/commands/window#arguments",
        "text": "Arguments",
        "level": 3
      },
      {
        "id": "api/commands/window#yields-learn-about-subject-management",
        "text": "Yields Learn about subject management",
        "level": 3
      },
      {
        "id": "api/commands/window#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/commands/window#no-args",
        "text": "No Args​",
        "level": 3
      },
      {
        "id": "api/commands/window#yield-the-remote-window-object",
        "text": "Yield the remote window object",
        "level": 4
      },
      {
        "id": "api/commands/window#check-a-custom-property",
        "text": "Check a custom property",
        "level": 4
      },
      {
        "id": "api/commands/window#start-tests-when-app-is-ready",
        "text": "Start tests when app is ready",
        "level": 3
      },
      {
        "id": "api/commands/window#options",
        "text": "Options",
        "level": 3
      },
      {
        "id": "api/commands/window#passes-timeout-through-to-should-assertion",
        "text": "Passes timeout through to .should() assertion",
        "level": 4
      },
      {
        "id": "api/commands/window#notes",
        "text": "Notes",
        "level": 2
      },
      {
        "id": "api/commands/window#cypress-uses-2-different-windows",
        "text": "Cypress uses 2 different windows.",
        "level": 3
      },
      {
        "id": "api/commands/window#rules",
        "text": "Rules",
        "level": 2
      },
      {
        "id": "api/commands/window#requirements-learn-about-chaining-commands",
        "text": "Requirements Learn about chaining commands",
        "level": 3
      },
      {
        "id": "api/commands/window#assertions-learn-about-assertions",
        "text": "Assertions Learn about assertions",
        "level": 3
      },
      {
        "id": "api/commands/window#timeouts-learn-about-timeouts",
        "text": "Timeouts Learn about timeouts",
        "level": 3
      },
      {
        "id": "api/commands/window#command-log",
        "text": "Command Log",
        "level": 2
      },
      {
        "id": "api/commands/window#history",
        "text": "History",
        "level": 2
      },
      {
        "id": "api/commands/window#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "content": {
    "type": "root",
    "children": [
      {
        "type": "heading",
        "depth": 1,
        "children": [
          {
            "type": "text",
            "value": "window"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Get the `window` object of the page that is currently active."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Syntax"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.window()cy.window(options)"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Usage"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Correct Usage"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.window()"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Arguments"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "options (Object)"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Pass in an options object to change the default behavior of `cy.window()`."
          }
        ]
      },
      {
        "type": "table",
        "align": [
          null,
          null,
          null
        ],
        "children": [
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Option"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Default"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Description"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`log`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`true`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Displays the command in the "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/core-concepts/open-mode.md#Command-Log",
                    "children": [
                      {
                        "type": "text",
                        "value": "Command log"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`timeout`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/configuration.md#Timeouts",
                    "children": [
                      {
                        "type": "text",
                        "value": "`defaultCommandTimeout`"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Time to wait for `cy.window()` to resolve before "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "#Timeouts",
                    "children": [
                      {
                        "type": "text",
                        "value": "timing out"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Yields "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/core-concepts/introduction-to-cypress.md#Subject-Management",
            "children": [
              {
                "type": "text",
                "value": "Learn about subject management"
              }
            ]
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`cy.window()` yields the `window` object."
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`cy.window()` is a query, and it is safe to chain further commands."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Examples"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "No Args"
          },
          {
            "type": "link",
            "title": null,
            "url": "#No-Args",
            "children": [
              {
                "type": "text",
                "value": "​"
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Yield the remote window object"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "End-to-End Test"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "Component Test"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.visit('http://localhost:8080/app')cy.window().then((win) => {  // win is the remote window})"
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.mount(<MyComponent />)cy.window().then((win) => {  // win is the remote window})"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Check a custom property"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "If the application sets a custom property, like:"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "window.tags = {  foo: 'bar',}"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Our test can confirm the property was properly set."
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.window().its('tags.foo').should('equal', 'bar')"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Note: Cypress commands are asynchronous, so you cannot check a property value before the Cypress commands ran."
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "it('equals bar', () => {  let foo  cy.window().then((win) => {    foo = win.tags.foo  })  // variable \"foo\" is still undefined  // because the above \"then\" callback  // has not been executed yet  expect(foo).to.equal('bar') // test fails})"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Instead, use "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/then.md",
            "children": [
              {
                "type": "text",
                "value": "`cy.then()`"
              }
            ]
          },
          {
            "type": "text",
            "value": " callback to check the value."
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "it('equals bar', () => {  let foo  cy.window()    .then((win) => {      foo = win.tags.foo    })    .then(() => {      // variable \"foo\" has been set      expect(foo).to.equal('bar') // test passes    })})"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Start tests when app is ready"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "If an application takes a while to start, it might \"signal\" its readiness by setting a property that Cypress can wait for."
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "// app.js// only set property \"appReady\" if Cypress is running testsif (window.Cypress) {  window.appReady = true}"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Cypress can wait for the property `window.appReady` to be `true` before every test"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "// spec.cy.jsbeforeEach(() => {  cy.visit('/')  cy.window().should('have.property', 'appReady', true)})"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "When Can The Test Start?"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "link",
            "title": null,
            "url": "https://www.cypress.io/blog/2018/02/05/when-can-the-test-start/",
            "children": [
              {
                "type": "text",
                "value": "This blog post"
              }
            ]
          },
          {
            "type": "text",
            "value": " explains how to use `cy.window()` to spy on the DOM `prototype` to detect when the application starts adding event listeners to the DOM elements. When this happens for the first time, Cypress knows that the application under test has started and the tests can begin."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Options"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Passes timeout through to "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/should.md",
            "children": [
              {
                "type": "text",
                "value": "`.should()`"
              }
            ]
          },
          {
            "type": "text",
            "value": " assertion"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.window({ timeout: 10000 }).should('have.property', 'foo')"
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Notes"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Cypress uses 2 different windows."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Let's say you want to check the type of the events. You might write code like below:"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "it('test', (done) => {  cy.get('#test-input').then((jQueryElement) => {    let elemHtml = jQueryElement.get(0)    elemHtml.addEventListener('keydown', (event) => {      expect(event instanceof KeyboardEvent).to.be.true      done()    })  })  cy.get('#test-input').type('A')})"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "It fails. But the interesting thing is that the type of `event` is `KeyboardEvent` when you `console.log(event)`."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "It's because Cypress uses an `iframe` to load the application under test. In other words, the `KeyboardEvent` used in the code above and the `KeyboardEvent` class from which the `event` variable is constructed are different `KeyboardEvent`s."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "That's why the test should be written like this."
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "it('should trigger KeyboardEvent with .type inside Cypress event listener', (done) => {  cy.window().then((win) => {    cy.get('#test-input').then((jQueryElement) => {      let elemHtml = jQueryElement.get(0)      elemHtml.addEventListener('keydown', (event) => {        expect(event instanceof win['KeyboardEvent']).to.be.true        done()      })    })  })  cy.get('#test-input').type('A')})"
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Rules"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Requirements "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/core-concepts/introduction-to-cypress.md#Chains-of-Commands",
            "children": [
              {
                "type": "text",
                "value": "Learn about chaining commands"
              }
            ]
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`cy.window()` requires being chained off of `cy`."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Assertions "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/core-concepts/introduction-to-cypress.md#Assertions",
            "children": [
              {
                "type": "text",
                "value": "Learn about assertions"
              }
            ]
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`cy.window()` will automatically "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/core-concepts/retry-ability.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "retry"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " until all chained assertions have passed"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Timeouts "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/core-concepts/introduction-to-cypress.md#Timeouts",
            "children": [
              {
                "type": "text",
                "value": "Learn about timeouts"
              }
            ]
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`cy.window()` can time out waiting for assertions you've added to pass."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Command Log"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Get the window"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.window()"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The commands above will display in the Command Log as:"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "When clicking on `window` within the command log, the console outputs the following:"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "History"
          }
        ]
      },
      {
        "type": "table",
        "align": [
          null,
          null
        ],
        "children": [
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Version"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Changes"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/changelog.md#0-20-0",
                    "children": [
                      {
                        "type": "text",
                        "value": "0.20.0"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Can call "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/focus.md",
                    "children": [
                      {
                        "type": "text",
                        "value": ".focus()"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " and "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/blur.md",
                    "children": [
                      {
                        "type": "text",
                        "value": ".blur()"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " on `cy.window()`"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/changelog.md#0-11-6",
                    "children": [
                      {
                        "type": "text",
                        "value": "0.11.6"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`cy.window()` logs to Command Log"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "See also"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/visit.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`cy.visit()`"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/document.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`cy.document()`"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/its.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`cy.its()`"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      }
    ]
  },
  "token_estimate": 912
}