Debugging JavaScript cookies
I'm debugging a site that sets cookies via javascript, and I'd like to know exactly which lines are setting cookies as I run the page. Simply combing through the script is not an option because its so convoluted.. (it's not my script if you're wondering)
How can I easily find out w开发者_如何学Chich lines are setting cookies? I'm new to this, so if you can explain the exact steps in doing this I'd be very thankful.
I presume that document.cookie is the only way to set cookies with javascript, but if there's another way(s) that'd definitely be helpful to know, as I might've ignored said lines in reading through the script..
Background: I'm on Windows XP
Yes, document.cookie
is how JS sets cookies. But remember:
Other parts of the page can set cookies. Cookies are primarily set in the HTTP response headers. Plugins, like Flash, set tons of cookies too.
The actual JS code that sets the cookie may be buried in a library.
It is possible that some programmers obfuscate the JS code, so that a search for "cookie" will fail.
Things to do:
Install the Web Developer add-on. This will allow you to easily see, edit, or delete cookies, for a given page -- including 3rd party cookies.
It also allows you to View the response headers -- to easily see if the cookies are being set that way. (clear cookies, reload the page, click: Information --> View Response Headers.)
Install the Firebug add-on and then the Firecookie plugin for Firebug.
Firecookie can show cookie events as they are happening. This, coupled with observation and use of JS breakpoints (Firebug feature) can help you narrow down where cookies are being manipulated.
Use firebug & firecookie to find the cookie's name. then search that name through the JS files using your IDE search feature.
精彩评论