cypress icon indicating copy to clipboard operation
cypress copied to clipboard

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

Open Jsijbel opened this issue 2 years ago • 38 comments

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

Jsijbel avatar Feb 21 '23 09:02 Jsijbel

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 avatar Feb 27 '23 16:02 flotwig

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.

Jsijbel avatar Feb 28 '23 09:02 Jsijbel

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

krpatter-intc avatar Apr 12 '23 22:04 krpatter-intc

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

wikstfre avatar Apr 28 '23 12:04 wikstfre

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

joaconigro avatar Jul 11 '23 19:07 joaconigro

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

StefanSakovic avatar Aug 29 '23 01:08 StefanSakovic

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

BevanR avatar Aug 29 '23 22:08 BevanR

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

StefanSakovic avatar Sep 03 '23 01:09 StefanSakovic

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.

corydeppen avatar Oct 17 '23 03:10 corydeppen

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

nathan5x avatar Oct 26 '23 20:10 nathan5x

Also having this issue - Chrome only

SimonFryPH avatar Nov 06 '23 10:11 SimonFryPH

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)

StefanSakovic avatar Nov 09 '23 19:11 StefanSakovic

exactly same issue here on Cypress [13.5.0]

burkedavid avatar Nov 16 '23 15:11 burkedavid

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)

mpoetzsch avatar Nov 21 '23 13:11 mpoetzsch

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. We're looking into if anything can be done with the Chrome's new logic.

jennifer-shehane avatar Nov 30 '23 16:11 jennifer-shehane

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

Does anyone see the same?

alexsch01 avatar Dec 01 '23 16:12 alexsch01

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

Nevermind.....I am now seeing this issue with cypress run

alexsch01 avatar Dec 12 '23 21:12 alexsch01

does any of you have a solution for headless mode.... since I upgraded chrome to v120 I can't find a solution for making chrome use http instead of https and yes it falls in loop in headless mode. I tried all above mentioned possible solutions but no success yet.

JohnnyTheBoy avatar Dec 13 '23 12:12 JohnnyTheBoy

@JohnnyTheBoy in my case I solved it by using this configuration

export default defineConfig({
  video: false,
  e2e: {
    baseUrl: 'http://localhost:4273',
    specPattern: '**/*.feature',
    chromeWebSecurity: true, //using true prevents the page reload loop
    defaultCommandTimeout: 10000, //Extended the default timeout, might be slower in docker
    experimentalModifyObstructiveThirdPartyCode: true,
    setupNodeEvents
  }
});

the chromeWebSecurity: true fixed the loop issue

joaconigro avatar Dec 13 '23 13:12 joaconigro

Well, the problem with setting chromeWebSecurity to false is that I can no longer manipulate iframes (as described in this post: https://www.cypress.io/blog/2020/02/12/working-with-iframes-in-cypress), so unfortunately that is not an option for me.

pjg avatar Dec 13 '23 13:12 pjg

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

JohnnyTheBoy avatar Dec 13 '23 13:12 JohnnyTheBoy

@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 :(

joaconigro avatar Dec 13 '23 14:12 joaconigro

I updated the workaround here: https://github.com/cypress-io/cypress/issues/25891#issuecomment-1861098656

alexsch01 avatar Dec 13 '23 18:12 alexsch01

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

JohnnyTheBoy avatar Dec 14 '23 09:12 JohnnyTheBoy

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.

jennifer-shehane avatar Dec 14 '23 15:12 jennifer-shehane

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

alexsch01 avatar Dec 14 '23 15:12 alexsch01

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

jennifer-shehane avatar Dec 14 '23 19:12 jennifer-shehane

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 avatar Dec 15 '23 23:12 alexsch01

@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

alexsch01 avatar Dec 17 '23 21:12 alexsch01

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

VolodymyrDmytriukhin avatar Dec 18 '23 14:12 VolodymyrDmytriukhin