{"record":{"id":"f8c35dd9245876bc","repo":"cypress-io/cypress","slug":"cy-origin-from-a-component-spec-is-not-allowed","errorCode":null,"errorMessage":"cy.origin from a component spec is not allowed","messagePattern":"cy\\.origin from a component spec is not allowed","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"npm/mount-utils/src/index.ts","lineNumber":46,"sourceCode":"  }\n\n  // When running component specs, we cannot allow \"cy.visit\"\n  // because it will wipe out our preparation work, and does not make much sense\n  // thus we overwrite \"cy.visit\" to throw an error\n  Cypress.Commands.overwrite('visit', () => {\n    throw new Error(\n      'cy.visit from a component spec is not allowed',\n    )\n  })\n\n  Cypress.Commands.overwrite('session', () => {\n    throw new Error(\n      'cy.session from a component spec is not allowed',\n    )\n  })\n\n  Cypress.Commands.overwrite('origin', () => {\n    throw new Error(\n      'cy.origin from a component spec is not allowed',\n    )\n  })\n\n  // @ts-ignore\n  Cypress.on('test:before:after:run:async', () => {\n    optionalCallback?.()\n  })\n}\n","sourceCodeStart":28,"sourceCodeEnd":56,"githubUrl":"https://github.com/cypress-io/cypress/blob/0d85fdc91230885bca0a91df278312800a48b727/npm/mount-utils/src/index.ts#L28-L56","documentation":"Thrown by @cypress/mount-utils setupHooks, which overwrites the `origin` command during component testing. cy.origin executes callbacks in a cross-origin frame reached via cy.visit; CT never visits a page and operates on a single mounted frame, so cross-origin execution has no valid target. The overwrite throws whenever the command is called.","triggerScenarios":"Calling `cy.origin(url, fn)` inside a component spec. Triggered for any CT run once setupHooks has installed the overwrites.","commonSituations":"Reusing an e2e cross-origin login flow inside a CT spec; testing a component that embeds a third-party iframe and attempting to drive the iframe via cy.origin; a shared support helper that abstracts cross-origin steps.","solutions":["Remove cy.origin from component specs; CT cannot drive cross-origin frames.","For third-party iframe content, stub the iframe or the network calls (cy.intercept) instead of driving the remote origin.","Move genuine cross-origin test flows to an e2e spec.","Split shared support so cross-origin helpers are only imported by e2e specs."],"exampleFix":"// before (component spec)\ncy.origin('auth.example.com', () => { cy.get('#user').type('sam') })\n// after — stub the auth call instead\ncy.intercept('POST', '/auth/login', { fixture: 'user.json' }).as('login')\ncy.mount(<App/>)","handlingStrategy":"type-guard","validationCode":"if (Cypress.testingType === 'e2e') {\n  cy.origin(url, fn)\n}","typeGuard":"const isE2E = (): boolean => Cypress.testingType === 'e2e'","tryCatchPattern":null,"preventionTips":["Keep cross-origin flows in e2e specs only.","Stub third-party iframes/network in CT via cy.intercept.","Lint against cy.origin in component spec files."],"tags":["component-testing","mount-utils","forbidden-command","cy-origin","cross-origin"],"backgroundTag":null,"analyzedSha":"0d85fdc91230885bca0a91df278312800a48b727","analyzedAt":"2026-08-12T16:24:28.056Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}