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

Option for using the exact domain when setting a Cookie #16856

Closed
jerrykobes opened this issue Jun 8, 2021 · 7 comments · Fixed by #25853
Closed

Option for using the exact domain when setting a Cookie #16856

jerrykobes opened this issue Jun 8, 2021 · 7 comments · Fixed by #25853
Assignees
Labels
topic: cookies 🍪 type: feature New feature that does not currently exist type: unexpected behavior User expected result, but got another

Comments

@jerrykobes
Copy link

jerrykobes commented Jun 8, 2021

What would you like?

An additional option within SetCookieOptions for cy.setCookie(name, value, options) that allows for setting an exact domain without a prepended period as described in #1896 .

Why is this needed?

When setting a cookie for a particular name/domain, if a cookie without a prepended period already exists in the browser then a second cookie with the same name will be created. This results in the browser having two cookies with the same name when the web application only expects one.

@jennifer-shehane jennifer-shehane added topic: cookies 🍪 type: unexpected behavior User expected result, but got another labels Jun 8, 2021
@Spea
Copy link

Spea commented Sep 28, 2021

@jennifer-shehane Is this something you consider adding? Can I somehow help with implementing this feature?

@Donaab
Copy link

Donaab commented Oct 5, 2021

Hi ... Is there any workaround that we can use until this is fixed?

@Songyu-Wang
Copy link
Contributor

@Donaab , I found that using document.cookie without specifying domain can be a workaround for basic use case

@Askarov5
Copy link

Askarov5 commented Jul 13, 2022

Are there any updates on this? or a workaround?
Unable to set HttpOnly flag with javascript blocked me from setting/copying needed cookies.

@Kazathur92
Copy link

@Songyu-Wang hi there, you said document.cookie could be used as a workaround. would you mind giving an example of how to do that? I am having the same issue as everyone else with Cypress adding a "." in the beginning of my cookie domain. :(

@garyantoriano
Copy link

Hi @Kazathur92, you can find more information about the document.cookie api at the following link: https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie
Basically if you use: document.cookie = "cookieName=cookieValue", it will set a cookie with its name as 'cookieName' and its value as 'cookieValue', and the domain name will be the host portion of the current document location.
So the additional dot character will only be added if you explicity include the domain name, ie:
document.cookie = "cookieName=cookieValue; domain=example.com"
In my case I also had to set the 'path' property as '/' to resolve my issues, otherwise it'll be the current path of the current document location.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Feb 25, 2023

Released in 12.7.0.

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

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Feb 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
topic: cookies 🍪 type: feature New feature that does not currently exist type: unexpected behavior User expected result, but got another
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants