I'd like to set breakpoints triggered when a cookie is being set, either by HTTP response header Set-Cookie or by DOM (JavaScript) document.cookie='cookie1=value1'.
I need this because when I go to some websites they have huge amount of requests and it's hard to find which one of those sets the cookie I'd like to inspect (to debug code around it).
Is this possible to do in Chrome, Firefox or any other browser?
The question asks for two ways how cookies can be set. So this requires two separate approaches.
Firebug had that feature back then, though to my knowledge none of the current developer tools have that feature.
For Chrome, I created a feature request to add that some time ago. And for Firefox there is also a feature request.
Until the browser vendors implement that feature you can use a workaround by manually setting the breakpoint(s).
To do that you have to search for "document.cookie" within all JavaScript sources and set (conditional) breakpoints where the property gets assigned a new value. And if the code uses the newer Cookie Store API, you have to do the same with "cookieStore.set".
document\.cookie\s*= or cookieStore\.set into the search field and hit Enter.cookiename === 'x', where cookiename is the name of the variable that holds the cookie name and 'x' is the name of the cookie you want to stop at.document.cookie or cookieStore.set into the search field and hit Enter.cookiename === 'x', where cookiename is the name of the variable that holds the cookie name and 'x' is the name of the cookie you want to stop at.document.cookie is being set / cookieStore.set() is being called.Set-Cookie headerAs the Set-Cookie header is part of a network request, the best place to look for it is the Network panel.
The headers are not directly shown in the list of requests. Though there is a way to search for them in the browsers. As both Chrome and Firefox offer a very similar UI, here are the steps for both:
Set-Cookie header is listed.The actual question here is obviously "Where does a specific cookie come from?".
To get a centralized answer to that question, I created a feature request for Firefox to add the origin information of cookies to the Storage Inspector some time ago.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With