Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Jsijbel opened this issue Feb 21, 2023 · 44 comments · Fixed by #28650
Closed
Assignees
Labels
E2E Issue related to end-to-end testing existing workaround topic: visit Problems with cy.visit command type: bug

Comments

@Jsijbel
Copy link

Jsijbel commented Feb 21, 2023

Current behavior

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

2023-02-21_10-39-18.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

@Jsijbel Jsijbel changed the title Test runner keeps reloading on redirect Test runner keeps reloading/refreshing on redirect Feb 21, 2023
@Jsijbel Jsijbel changed the title Test runner keeps reloading/refreshing on redirect Test runner keeps reloading on redirect Feb 21, 2023
@flotwig
Copy link
Contributor

flotwig commented Feb 27, 2023

Thanks for opening an issue @Jsijbel. Confirmed that I can reproduce this behavior. Is there a specific version this started occurring on for you?

It seems like there is a 301 and two 302's before landing back on inloggen, possibly this redirect chain is causing Cypress to become confused:
image

I'll get this routed and prioritized for a fix.

@flotwig flotwig added type: bug topic: visit Problems with cy.visit command routed-to-e2e E2E Issue related to end-to-end testing labels Feb 27, 2023
@Jsijbel
Copy link
Author

Jsijbel commented Feb 28, 2023

Thank your for your response and acknowledgement.
I honestly can't remember when this issue wasn't present, and we have been working with cypress in our teams for several years now. Normally this isn't a real issue for us as we collect the authentication programmatically in most cases, however for a new test case this is causing issues for us.

@krpatter-intc
Copy link

Was curious if there was a workaround ever found for this issue? I think I am perhaps hitting a similar issues (v12.9.0)

@nagash77 nagash77 added Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team. and removed routed-to-e2e labels Apr 19, 2023
@wikstfre
Copy link

wikstfre commented Apr 28, 2023

I am also curious about some workaround. Also having this issue (12.11.0) with an Angular app (redirects when authenticating).

@joaconigro
Copy link

Hi, I'm having the same issue. Is there any news about this problem? or any workaround? Thank you

@StefanSakovic
Copy link

I have the same problem..any news about this bug?

@BevanR
Copy link

BevanR commented Aug 29, 2023

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).

@StefanSakovic
Copy link

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).

As first,
Thanks a lot for solving our problem..
But need to ask..is it correct to leave tests like that...I mean is it good to work
only on http protocol instead of both? Thanks

@corydeppen
Copy link

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.

@nathan5x
Copy link

@flotwig - Our team is also facing the same issue. URL starts with https. This problem is happening only on Chrome. Firefox works perfectly fine.

@SimonFryPH
Copy link

Also having this issue - Chrome only

@StefanSakovic
Copy link

Also having this issue - Chrome only

Cypress suport only http protocol.
Use http protocol instead of https..like this example:

*EROR

httpS://www.someexampe.com(when u test website with https its strating realoding)

acceptable :

http://www.someexampe.com (when u test website with http its NOT reloading)

@burkedavid
Copy link

exactly same issue here on Cypress [13.5.0]

@mpoetzsch
Copy link

mpoetzsch commented Nov 21, 2023

To summarize, the issue arises only with newer versions of Chrome (it worked for me with an older version). The problem likely started with the introduction of https://blog.chromium.org/2023/08/towards-https-by-default.html.

Workaround:
change the URL from https to http in the address bar of chrome and reload the web specs runner. After that, the tests run smoothly.

or a more permanent workaround is here:
https://superuser.com/questions/565409/how-to-stop-an-automatic-redirect-from-http-to-https-in-chrome/881431
(the solution with the most upvotes)

@jennifer-shehane jennifer-shehane changed the title Test runner keeps reloading on redirect cypress reloads in infinite loop when calling cy.visit to http URL that upgrades to https. Nov 29, 2023
@jennifer-shehane jennifer-shehane removed the Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team. label Nov 29, 2023
@joaconigro
Copy link

@joaconigro It's not working for me.... Can you confirm that you have chrome v120

Actually, I'm not using Chrome, but Microsoft Edge v120. I thought it should work as well :(

@alexsch01
Copy link
Contributor

alexsch01 commented Dec 13, 2023

I updated the workaround here: #25891 (comment)

@JohnnyTheBoy
Copy link

@alexsch01 Nope..... still not working with Cypress v 13.6.1 and Chrome v120 .... you can test that by adding code to the scaffolded cypress tests.

@jennifer-shehane
Copy link
Member

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.

@alexsch01
Copy link
Contributor

alexsch01 commented Dec 14, 2023

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

@jennifer-shehane
Copy link
Member

Yah I can recreate this infinite loop with this example which has no https protocol.

Screen Shot 2023-12-14 at 2 42 13 PM

it('loops forever', () => {
  cy.visit('http://http.badssl.com/')
})

http://g.recordit.co/YPnzoQlmU1.gif

@alexsch01
Copy link
Contributor

alexsch01 commented Dec 15, 2023

Lets say test1 and test2.com are both in the host file and they go to the same IP Address
and there is no https version

cy.visit('http://test') - won't have the looping issue
cy.visit('http://test2.com') - will have the looping issue

for the httpforever.com example

cy.visit('http://146.190.62.39') - won't have the looping issue
cy.visit('http://httpforever.com') - will have the looping issue

@alexsch01
Copy link
Contributor

alexsch01 commented Dec 17, 2023

@jennifer-shehane In DevTools running in Cypress Chrome window,
location.href = location.href.replace(location.origin, 'http://httpforever.com')
It automatically upgrades it to https

@VolodymyrDmytriukhin
Copy link

I have also issue with opening http protocol - tried chromeWebSecurity: true - but strange that in 1 application it worked, but in another doesn't.
Issue occurred after updating to chrome 120
Not reproducible on Firefox 120

@jennifer-shehane jennifer-shehane changed the title cypress reloads in infinite loop when calling cy.visit to http URL that upgrades to https or 301/302 redirect. cypress reloads in infinite loop when calling cy.visit to http URL that upgrades to https. Dec 18, 2023
@jennifer-shehane
Copy link
Member

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

@alexsch01
Copy link
Contributor

alexsch01 commented Dec 18, 2023

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,

@VolodymyrDmytriukhin
Copy link

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://'))
}

@alexsch01 this part of code is not working - because top is not a variable or function - looks like it should be executed as a browser JS injection

@alexsch01
Copy link
Contributor

@VolodymyrDmytriukhin just tested on Linux, NodeJS 12.16.3, Cypress 10.0.0 - it works for me with chromium and electron

@alexsch01
Copy link
Contributor

@jennifer-shehane I made repo to reproduce the issue: https://github.com/alexsch01/testing

@jennifer-shehane
Copy link
Member

Yah we can reproduce the issue and are working on a solution which requires some changes on the App as well as some manual changes to Chrome settings for users who have already encountered this issue to their hsts domain settings. It shouldn't cause an infinite loop for users in the future who haven't encountered it once though. Most of our team is on holiday this week however, so the solution will be delayed.

@alexsch01
Copy link
Contributor

@jennifer-shehane Thanks. I made a bug report with Chromium: https://bugs.chromium.org/p/chromium/issues/detail?id=1513507, since it could be a Chromium bug

@jennifer-shehane
Copy link
Member

@alexsch01 Thanks for opening the issue. It does seem like they're not doing something correctly here.

@tudorgabriel
Copy link

@jennifer-shehane Thanks. I made a bug report with Chromium: https://bugs.chromium.org/p/chromium/issues/detail?id=1513507, since it could be a Chromium bug

just FYI the issue is also present on the Chromium version < 100.

@tudorgabriel
Copy link

Screen.Recording.2024-01-11.at.22.39.48.mov

Still not working properly

@alexsch01
Copy link
Contributor

alexsch01 commented Jan 11, 2024

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

@ir2508front
Copy link

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).

I removed the 's' from https then it works for me. Thank you

@jennifer-shehane
Copy link
Member

We're trying to get a release out for this today.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jan 17, 2024

Released in 13.6.3.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v13.6.3, please open a new issue.

@cypress-bot cypress-bot bot removed the stage: investigating Someone from Cypress is looking into this label Jan 17, 2024
@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Jan 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
E2E Issue related to end-to-end testing existing workaround topic: visit Problems with cy.visit command type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.