In the following example we used cy.visit("/cypress.json").

When this happens Cypress gets a successful 200 OK response, and then proceeds to handle the visit.
Unfortunately because our responses' Content-Type was application/json and not text/html, the normal HTML injection completely fails, the browser is super confused, and renders the source inline.
Also, the error you get is super confusing.
Why this is happening
As of 0.17.0 you cannot visit non text/html responses, so this actually should error but we should actually take this into account and provide a very nice error message explaining that you can't use cy.visit but you can instead use cy.request.
The use case around doing this is that some users don't want to load their full app's UI, and instead just want to hit a single JSON API endpoint in order to get cookies served to them. Using cy.request is exaclty what you want to use.
In the following example we used
cy.visit("/cypress.json").When this happens Cypress gets a successful
200 OKresponse, and then proceeds to handle the visit.Unfortunately because our responses'
Content-Typewasapplication/jsonand nottext/html, the normal HTML injection completely fails, the browser is super confused, and renders the source inline.Also, the error you get is super confusing.
Why this is happening
As of
0.17.0you cannot visit nontext/htmlresponses, so this actually should error but we should actually take this into account and provide a very nice error message explaining that you can't usecy.visitbut you can instead usecy.request.The use case around doing this is that some users don't want to load their full app's UI, and instead just want to hit a single JSON API endpoint in order to get cookies served to them. Using
cy.requestis exaclty what you want to use.