cypress: cypress reloads in infinite loop when calling cy.visit to http URL that upgrades to https.

Current behavior

When visiting a page that triggers certain redirects, the test runner keeps reloading and looping endlessly.

https://user-images.githubusercontent.com/39823861/220307457-9c30ff6e-a37d-4abf-b370-2431082d3aae.mp4

Desired behavior

Not reload the test runner and follow redirects.

Test code to reproduce

describe('example cypress reload issue', () => {
  it('keeps reloading', () => {
    cy.visit('https://enexis.nl/mijn-enexis/mijn-aanvragen')
  })
})

Cypress Version

12.6

Node version

18.12.1

Operating System

Win 11

Debug Logs

No response

Other

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 4
  • Comments: 44 (20 by maintainers)

Most upvoted comments

We observed this unexpected looping behaviour when Cypress was running on https:// in the Chrome browser that it was driving. The server for our system under test (SPA web app) only supports the http:// protocol. When we manually removed the s in the URL bar in the Cypress-driven Chrome, it began behaving as expected again (no looping).

Between our tests running fine on Firefox and the comment above by @BevanR (thank you!), I’m wondering if this may be related to Chrome’s recent change to use HTTPS by default.

We’re narrowing in on a solution. So will hopefully have some updates soon on this.

UPDATED

Below instructions works around the issue, until a proper solution is made

Both PART1 and PART2 are required


PART1 - in it block

if(top.location.protocol == 'https:') {
    top.history.replaceState('', '', top.location.href.replace('https://', 'http://'))
}
cy.visit('http://httpforever.com')

PART2 - in cypress config

chromeWebSecurity: false,

Hi, I’d like to get some understanding on why this workaround doesn’t work for people. To visit the correct URL to begin with. Is there a reason you need to visit the http or https and have it resolve to the other protocol?

We would recommend having your cy.visit visit the correct protocol (http/https) to avoid the redirection loop for now to get around this issue.

Internal (not exposed to the Internet) company apps generally use http

  • I am using the correct protocol (http) for the URL I’m visit’ing

@tudorgabriel the fix on Cypress’s side isn’t released yet

I am only seeing this with cypress open, I don’t see this with cypress run

Does anyone see the same?