Skip to content
Latchkey

Cypress "Cypress detected a cross origin error" in CI

Cypress runs commands against a single superdomain. When a flow redirects to a different origin (an SSO login, a payment domain), Cypress throws a cross origin error unless you wrap the other-origin interactions in cy.origin(). This surfaces in CI exactly as it does locally, but full auth flows are more common in CI.

What this error means

A test fails with "Cypress detected a cross origin error happened on page load: ... Blocked a frame with origin ... from accessing a cross-origin frame" after a redirect to another domain.

cypress
Cypress detected a cross origin error happened on page load:

  > Blocked a frame with origin "https://app.example.com" from accessing a
    cross-origin frame.

A cross origin error happens when your application navigates to a new URL which
does not match the origin policy above.

Common causes

The flow navigates to a second origin

An external login or payment redirect moves to a different superdomain, which Cypress blocks by default.

Other-origin interactions not wrapped in cy.origin()

Commands meant to run on the second origin run outside cy.origin(), so Cypress refuses them.

How to fix it

Wrap other-origin steps in cy.origin()

Run the commands that touch the second domain inside cy.origin() with that origin as the argument.

cypress/e2e/login.cy.js
cy.origin('https://auth.example.com', () => {
  cy.get('#username').type('ada');
  cy.get('#password').type('secret');
  cy.contains('Sign in').click();
});

Bypass the third-party UI where possible

Program a session directly (API login, set tokens) so the test does not cross origins at all.

cypress/e2e/login.cy.js
cy.session('user', () => {
  cy.request('POST', '/api/login', creds);
});

How to prevent it

  • Wrap every cross-origin interaction in cy.origin().
  • Prefer programmatic login over driving third-party auth UIs.
  • Keep tests on one superdomain when the product allows it.

Frequently asked questions

What causes ""Cypress detected a cross origin error""?
An external login or payment redirect moves to a different superdomain, which Cypress blocks by default.
How do I fix "Cypress detected a cross origin error"?
Run the commands that touch the second domain inside cy.origin() with that origin as the argument.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card