DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk5 min

How to Test Multi-Domain Workflows with Cypress cy.origin()

Use top-level cy.origin() blocks to interact with secondary origins in Cypress tests, pass data with args, and handle version and browser-context limits.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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:

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Respect the origin-block boundaries

  • Do not nest cy.origin() calls. Handle each origin change in successive top-level blocks.
  • cy.intercept() and cy.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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.