Use cy.origin() to continue a Cypress end-to-end test after it navigates to a different origin. Put commands for the destination page inside a top-level cy.origin() callback whose origin matches the destination’s scheme, hostname (including subdomain), and port. Since Cypress 14, this applies to sibling subdomains as well as unrelated domains.
What counts as a different origin?
An origin consists of a scheme, hostname, and port. A change in any of these makes a different origin: for example, https versus http, login.example.test versus app.example.test, or a different port. The origin passed to cy.origin() must match the destination precisely. A path or query string does not change an origin.
As an Amazon Associate I earn from qualifying purchases.
Cypress 12 made cy.origin() generally available for end-to-end tests. Cypress 14 stopped injecting document.domain by default, so tests must use origin blocks for distinct origins, including sibling subdomains. See the Cypress cy.origin() documentation and its cross-origin testing guide.
Put destination interactions in the matching origin block
A test may reach the destination by clicking a link, following a redirect, or visiting it directly. Once there, run commands that inspect or interact with that page inside a matching cy.origin() block.
#1 Best Overall
cy.visit('https://app.example.test')
cy.get('[data-cy="sign-in"]').click()
cy.origin('https://login.example.test', { args: { email } }, ({ email }) => {
cy.get('[name="email"]').type(email)
cy.get('[type="submit"]').click()
})
// After the app redirects back to its own origin, continue there.
cy.get('[data-cy="account-menu"]').should('be.visible')
Here, clicking Sign in takes the browser to the login origin. The callback handles the login page; after the app returns to its starting origin, the test can continue there.
Visiting the secondary origin directly
You can also visit the destination before entering its origin block, or call cy.visit() inside the block:
Rank #2
cy.visit('https://app.example.test')
cy.visit('https://docs.example.test')
cy.origin('https://docs.example.test', () => {
cy.get('h1').should('be.visible')
})
For a workflow that crosses several origins, use a separate, top-level cy.origin() block for each destination.
Pass values with args, not outer variables
The callback is serialized and evaluated in the secondary origin. It is not a closure, so it cannot read variables from the surrounding test unless you pass them explicitly. Use the args option for serializable data, as in the email example above. Keep the callback self-contained and pass only the values it needs.
Rank #3
Respect the origin-block boundaries
- Do not nest
cy.origin()calls. Handle each origin change in successive top-level blocks. cy.intercept()andcy.session()are not allowed inside an origin callback.cy.origin()supports top-level page navigation; it does not provide access to a different tab, window, popup, or cross-origin iframe.- Cypress documents HTTPS-to-HTTP navigation as an error and requires URLs navigated in one test to use the same port. Match the actual scheme and port rather than treating the hostname alone as the origin.
For further boundaries and browser details, consult the official cross-origin testing guide and the web security guide.
Choose the right test boundary for the destination
A destination your team controls
Use the real navigation and interact with the destination in cy.origin() when the behavior is part of the journey your application owns. This can cover the application-controlled parts of an SSO, OAuth, or OIDC flow.
Rank #4
An uncontrolled third-party site
If your application sends users to an external site you do not control, Cypress recommends asserting the outbound link’s href rather than automating the third-party site. That keeps the test focused on your application instead of depending on another service’s availability and behavior.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
A response check without browser interaction
cy.request() may suit a check of an HTTP response, but it does not test a user’s browser interaction with the destination. Use it only when that narrower assertion answers the question the test is meant to cover.
An embedded cross-origin iframe
cy.origin() does not enable Cypress to interact with a cross-origin iframe. Treat the iframe as an integration boundary and test the parts your application controls; do not assume top-level origin support applies to embedded frames.
Migrate older tests for Cypress 14
Cypress 14 no longer injects document.domain by default. Tests that previously relied on that behavior need explicit origin blocks when they cross between distinct origins, even sibling subdomains. Cypress provides the deprecated injectDocumentDomain setting as a transition aid, but it has compatibility caveats, including possible unexpected behavior on sites using the Origin-Agent-Cluster header and a documented WebKit support caveat. Prefer updating tests to use cy.origin() rather than relying on the setting. See the Cypress migration guide.
Disabling web security is not the normal fix for a missing origin block. Cypress documents it only as a bypass for cases that cannot otherwise be worked around; it does not turn cross-origin iframe access into a portable Cypress capability.
Troubleshoot common cy.origin() failures
| Symptom | Likely cause | Fix |
|---|---|---|
| A selector command fails after navigation, although the browser is on the destination page. | The command is running outside the destination’s origin context. | Move the destination’s assertions and interactions into a matching cy.origin() callback. |
| Cypress rejects the origin or the block does not match the destination. | The origin string omits or mismatches the scheme, subdomain, or port. | Use the destination’s exact scheme, hostname, and port. Remember that sibling subdomains are distinct origins. |
| The callback reports that a variable is unavailable. | The serialized callback cannot access lexical variables from the outer test. | Pass serializable values through { args: ... } and accept them as callback parameters. |
| A command is rejected inside the callback or Cypress reports an invalid nested origin. | The callback nests another origin block or uses a prohibited command. | Use successive top-level origin blocks; keep cy.intercept() and cy.session() outside origin callbacks. |
| The test attempts to act in a popup, another tab, or an embedded frame. | Those are different browsing contexts, not top-level origin navigation supported by cy.origin(). |
Redesign the test around the application-controlled integration boundary. For an outbound link, assert its href where appropriate. |
| A cross-origin transition fails between HTTP and HTTPS, or across ports. | Cypress documents HTTPS-to-HTTP navigation as an error and requires URLs navigated in one test to use the same port. | Use a compatible test environment and verify the exact destination scheme and port before adding the origin block. |
Or skip the browser setup
For a screenshot of a page rather than an interactive Cypress test, ScreenshotNeo offers a one-call capture API. The URL is the only required page input; see the ScreenshotNeo API documentation for options.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
ScreenshotNeo accepts cookie and consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf for AI agents. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots. This captures pages; it does not replace Cypress assertions or test browser interactions.
Sign up free for 1,000 screenshots a month, with no card required.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →




