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

Fix issue with the timing of setting cookies in the browser #23531

Closed
chrisbreiding opened this issue Aug 24, 2022 · 5 comments · Fixed by #23643
Closed

Fix issue with the timing of setting cookies in the browser #23531

chrisbreiding opened this issue Aug 24, 2022 · 5 comments · Fixed by #23643
Assignees
Labels
topic: cookies 🍪 topic: cross-origin ⤭ Topics related to cross-origin navigation in tests topic: cy.origin Problems or enhancements related to cy.origin command

Comments

@chrisbreiding
Copy link
Contributor

Currently, if a cross-origin request sets a cookie and the app attempts to read the cookie via document.cookie synchronously on page load, the document.cookie value will not be correct / up-to-date.

Spec:

it('document.cookie includes cookie set by http request', () => {
  cy.get('[data-cy="cookie-login-land-on-document-cookie"]').click()
  cy.origin('http://foobar.com:3500', { args: { username } }, ({ username }) => {
    cy.get('[data-cy="username"]').type(username)
    cy.get('[data-cy="login"]').click()
  })

  cy.origin('http://idp.com:3500', { args: { username } }, ({ username }) => {
    cy.get('[data-cy="document-cookie"]').invoke('text')
    .should('include', `user=${username}`)
  })
})

App:

<p>
  <strong>document.cookie:</strong>
  <span data-cy="document-cookie"></span>
</p>
<script>
  document.querySelector('[data-cy="document-cookie"]').textContent = document.cookie;
</script>
@boylec
Copy link

boylec commented Aug 27, 2022

I believe this is likely the cause of #23565 as I am seeing the same behavior as the OP in that issue and it appears that it is due to the client side app not being able to read a cookie that was set on page load during a sequence of redirects/XHR requests that makeup the login process of the underlying app.

@boylec
Copy link

boylec commented Aug 27, 2022

I rolled back to 10.2 and my test started working again.

@boylec
Copy link

boylec commented Aug 27, 2022

Not sure how helpful this is, but my particular test is good to go up to 10.3.

When run from 10.3.1 my test fails in a unique way unlike 10.4+
When run from 10.4+ my test fails as described in #23565

Let me know if any more detail would be helpful, I'll do the best I can.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Oct 18, 2022

The code for this is done in cypress-io/cypress#23643, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Oct 25, 2022

Released in 10.11.0.

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

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Oct 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
topic: cookies 🍪 topic: cross-origin ⤭ Topics related to cross-origin navigation in tests topic: cy.origin Problems or enhancements related to cy.origin command
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants