cypress icon indicating copy to clipboard operation
cypress copied to clipboard

Option for using the exact domain when setting a Cookie

Open jerrykobes opened this issue 4 years ago • 6 comments

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 https://github.com/cypress-io/cypress/issues/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.

jerrykobes avatar Jun 08 '21 18:06 jerrykobes

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

Spea avatar Sep 28 '21 16:09 Spea

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

Donaab avatar Oct 05 '21 12:10 Donaab

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

Songyu-Wang avatar Oct 20 '21 16:10 Songyu-Wang

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

Askarov5 avatar Jul 13 '22 15:07 Askarov5

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

Kazathur92 avatar Sep 02 '22 03:09 Kazathur92

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.

garyantoriano avatar Nov 23 '22 21:11 garyantoriano

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[bot] avatar Feb 25 '23 02:02 cypress-bot[bot]