Skip to content

using cy.visit on non text/html contents bombs on injection #211

@brian-mann

Description

@brian-mann

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

screen shot 2016-09-06 at 12 18 51 am

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions