question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prepending Stale Cookies to requests after 10.3

See original GitHub issue

Current behavior

We use cy.session+cy.origin (see code below) to login with Keycloak which is hosted on a different domain. This always worked well until updating from Cypress 10.2 to 10.3.

After the first tests, the session seems broken, although Cypress logs “Validate Session: valid”. Authentification is no longer established. When I add a cy.wait(1000) between visit and contains in the test code of it('starts again' I can see that the browser is at the login screen again. There is also this error:

Timed out after waiting 60000ms for your remote page to load on origin(s):
- http://localhost:4200
A cross-origin request for https://login… was detected.

Same happens even for the first test if I rerun all tests using the “Run All Tests” button.

Desired behavior

Cypress should be able to store and recover the session (cookies?), as it already did before 10.3.

Test code to reproduce

In support/commands.ts:

Cypress.Commands.add('cachedLogin', () => {
    const args = { user };
    cy.session(
        args,
        () => {
            cy.visit('/');
            cy.origin(KEYCLOAK_DOMAIN, { args }, ({ user }) => {
                cy.get('#username').type(user.username);
                cy.get('#password').type(user.password);
                cy.get('#kc-login').click();
            });
            cy.url().should('contain', Cypress.config('baseUrl'));
        },
        {
            validate() {
                cy.request('/').its('status').should('eq', 200);
            },
        }
    );
});

In Cypress-issue-22751.cy.ts:

describe('issue 22751 reproducer', () => {
    beforeEach(() => {
        cy.cachedLogin();
    });

    it('starts', () => {
        cy.visit('/');
        cy.contains('Start');
    });

    it('starts again', () => {
        cy.visit('/');
        // cy.wait(1000); // add line to see that browser is at login screen
        cy.contains('Start'); // fails on Cypress 10.3; "Timed out after waiting 60000ms for your remote page to load on origin(s):"
    });
});

Cypress Version

10.3, 10.3.1, 10.4

Other

Tested with Chrome, Edge, Electron.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:20 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
sebkasanzewcommented, Aug 6, 2022

@AtofStryker Here is a repo with the reproducible error https://github.com/Sebkasanzew/cypress-issue-22751.

It was easier than I thought 😅. Thanks for the template @iomedico-beyer .

1reaction
AtofStrykercommented, Aug 8, 2022

@sebkasanzew I was able to clone your reproduction and was able to reproduce the issue. I am pretty sure I know what the issue is, as we prepend updated cookies to the request and do not remove the stale values. This also explains why the cookie size is just about double on the request. We likely need to adapt this logic to override the previous cookie values, which should lead to expected behavior.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Sessions and Session Persistence - Oracle Help Center
This chapter describes how to set up and use sessions and session persistence in WebLogic Server 10.3.6.
Read more >
How to send cookies in a post request with the Python ...
import requests cookies = {'enwiki_session': ... If you want to pass the cookie to the browser, you have to append to the headers...
Read more >
Cy10 multi domain: redirect triggered keycloak login form is ...
Timed out retrying after 4000ms: Expected to find element: #username, but never found it. ... Prepending Stale Cookies to requests after 10.3 #22751....
Read more >
RFC 3261: SIP: Session Initiation Protocol
SIP makes use of elements called proxy servers to help route requests to the ... Since the softphone does not know the location...
Read more >
Headers.append() - Web APIs | MDN
The append() method of the Headers interface appends a new value onto an existing header inside a Headers object, or adds the header...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found