You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Hi everyone, I'm sorry you're having these issues!
In order to support cy.origin(), Cypress patchesXMLHttpRequest in the iframe that your application is loaded in. In this patch, XMLHttpRequest.prototype.send is modified to always be asynchronous.
Unfortunately, this causes an issue if you open() the XMLHttpRequest with false as the third parameter, flagging that request as synchronous: open() will return immediately, and if you do not ensure the request's readyState property is 4 ("Done") before parsing the request, errors can occur.
Synchronous XMLHttpRequests have been deprecated for some time because they cause hangs with poor network conditions.
@alecmestroni , can you update your code to use an asynchronous XMLHttpRequest? The context for the synchronous XMLHttpRequest in the reproduction case you provided is in the main-$HASH.js asset (this is bundled and minified, so it may take some effort to track down in your codebase):
@cacieprins thanks for the answer.
Since this is coming from a third-party dependency, I don’t have direct control over the code causing the issue. However, I would like to know if there is any way I can address or work around this problem on my side. For example, is there a way to configure Cypress or the test environment to allow for synchronous requests, or any other potential solutions I can implement to mitigate this? (in addition to the issue)
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
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
The text was updated successfully, but these errors were encountered: