cypress
cypress copied to clipboard
Option for using the exact domain when setting a Cookie
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.
@jennifer-shehane Is this something you consider adding? Can I somehow help with implementing this feature?
Hi ... Is there any workaround that we can use until this is fixed?
@Donaab , I found that using document.cookie without specifying domain can be a workaround for basic use case
Are there any updates on this? or a workaround?
Unable to set HttpOnly flag with javascript blocked me from setting/copying needed cookies.
@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. :(
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.
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.