Skip to content

cy.origin() causes async issue with GET request (JSON parsing error) -> Unexpected end of JSON input #31195

@alecmestroni

Description

@alecmestroni

Current behavior

When visiting a page using cy.visit() inside cy.origin(), a subsequent GET request to download a JSON file causes a problem. The request is asynchronous, and Cypress loses sync inside cy.origin(). As a result, Cypress tries to parse the response (JSON) before it has been fully downloaded, causing a JSON parsing error.
Visiting the page outside of the cy.origin causes no problem.

Actual behavior: The JSON file is not fully downloaded before the client attempts to parse it, causing a parsing error.

Desired behavior

Expected behavior: Cypress should wait for the GET request to finish downloading the JSON file before attempting to parse it.

Test code to reproduce

describe("Testing Cross Origin", () => {
  it("test", () => {
    cy.visit('www.google.com');
    cy.origin('https://demoportal-stage.infocert-labs.eu', () => {
      cy.visit('https://demoportal-stage.infocert-labs.eu/login')
    })
  });
});

Cypress Version

13.17.0 or 14.1.0

Node version

v20.18.3

Operating System

Edition Windows 11 Enterprise Version 24H2 Installed on ‎20/‎01/‎2025 OS build 26100.3194 Experience Windows Feature Experience Pack 1000.26100.48.0

Metadata

Metadata

Assignees

Labels

staleno activity on this issue for a long periodtopic: cy.originProblems or enhancements related to cy.origin commandtype: bug

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions