cypress: Cypress is unable to load site in v3.5.0 due to "Parse Error"
Current behavior:
When attempting to resolve our site, Cypress throws an error. This was not an issue on older versions of Cypress. Our NGINX config is fairly vanilla and hasnt changed since we deployed it several months ago
error
CypressError: cy.visit() failed trying to load:
https://our-website.test.com/search-page
We attempted to make an http request to this URL but the request failed without a response.
We received this error at the network level:
> Error: Parse Error
Common situations why this would fail:
- you don't have internet access
- you forgot to run / boot your web server
- your web server isn't accessible
- you have weird network configuration settings on your computer
The stack trace for this error is:
Error: Parse Error
at TLSSocket.socketOnData (_http_client.js:451:22)
at TLSSocket.emit (events.js:194:13)
at addChunk (_stream_readable.js:296:12)
at readableAddChunk (_stream_readable.js:277:11)
at TLSSocket.Readable.push (_stream_readable.js:232:10)
at TLSWrap.onStreamRead (internal/stream_base_commons.js:165:17)
Because this error occurred during a 'before each' hook we are skipping the remaining tests in the current suite: 'Search Page tests'`
Desired behavior:
Our site loads on newer versions of Cypress (3.5.0) and up.
Steps to reproduce: (app code and test code)
example code:
/// <reference types="Cypress" />
describe('Search Page Tests', () => {
beforeEach(() => {
cy.visit('/search')
})
cy.get(`[data-qa='tabs-wrapper']`).get(`[data-qa='tab']`).contains('red').as('redButton')
cy.get(`[data-qa='tabs-wrapper']`).get('[data-qa="tab"]').contains('blue').as('blueButton')
})
it('visit the search page and search for buttons', () => {
cy.getById('searchGoToHomeButton')
.should('have.attr', 'href', '/home')
});
Steps to reproduce.
npx cypress open
Click spec from GUI and let test start. Error is thrown immediately upon attempting to resolve the page.
Versions
v3.5.0
Cypress desktop, v3.5.0, MAcOS 10.13.6, Electron(Chrome v78)
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 2
- Comments: 44 (15 by maintainers)
After doing some investigation into the “Parse Error: Invalid header value char”, it comes down to a change in Node.js that was made in Node.js 11.5.0: nodejs/node#24730
The
llhttpHTTP parser replaced the oldhttp_parserHTTP parser. The newer one is more maintainable; however, it also seems to be much stricter about what can be in an HTTP header. Since Cypress uses Node’s HTTP library to proxy requests to your site, invalid characters in the header will now give this error.In Cypress 3.5.0, the bundled Node.js version was upgraded to > 11.5.0 (#5849), introducing this bug.
Here is a bug in the Node.js repo talking about this issue with
llhttpand some proposed fixes: nodejs/node#30573I believe that, in the meantime, we may be able to pass the
--http-parser=legacyoption to opt out of using the newllhttpparser. I will work on creating a test that reproduces the “Invalid header value char” issue as well as a fix.In the meantime, a workaround would be to ensure that the headers sent by your server do not contain any special characters that are illegal in an HTTP header.
@gabbersepp I cannot share details of scripts or website over here, however I have already sent an email with some details to cypress support team.
We are also getting exactly same issue. With cypress version 3.4.1 every application works fine, however when we try to upgrade to latest versions (3.6.0+) then cypress is not able access the site (throwing the same error shared bytes @tmonteith ).
Apparently, something changed between 3.4.1 to latest versions of cypress that is causing issue. Note that we are also using ngnix and same configurations that work fine with c.ypress 3.4.1, do not work with cypress 3.6.0. @jennifer-shehane
@natkrish We are waiting for https://github.com/electron/electron/pull/21694 to be released in Electron 9 so we can use it. Once we can use
--http-parser=legacy, we can fix this finally.In the meantime, the only workaround is to update your web server to send headers that do not contain non-printable ASCII characters.
@flotwig I put up an example that throws the “Parse Error: Invalid header value char” error on just a simple
cy.visit().@flotwig Using 3.8.0 we get the same “Parse Error” in some environments, but not others. Here’s the
Set-Cookieheader for the one that does not workwhile this one does work with no problems
Could it be the lowercase format?
Edit. I just saw that with the latest update we’re now getting a “Parse Error: Invalid header value char” and not just the “Parse Error” we had from 3.5.0 and up.