Testing Cookies
I recently came a cross an issues that I needed to test in Safari (on a Mac obviously). I needed to see how a page looked with a cookie present. But I only had the page in a development environment and the page that created the cookie was in a production environment, for various reasons I was not able to hit the page that created the cookie in my development environment.
So, I had to find a way to manually create the cookie in Safari, a quick Google search for a Safari Web Developer tool bar or something that would allow me to manually create cookies yielded nothing useful. So I took a walk to get a cup of Joe and thought about it a bit. This is what I came up with….
Run some JavaScript in the address bar!!! Now others may have done this already, I’m not claiming I came up with the idea but it was the first time I thought of doing it. So this is what I wrote (the values have been changed to protect the innocent).
- javascript:document.cookie="user=me;expires=December 29 2007 00:00:00; path=/;domain=michaelnoga.com";
Simple copy that whole line and past it into your address bar and hit enter. Now you have a cookie called user with a value of me. Wahoo!!!! This works in Firefox as well as Safari, I have not tested in IE since I don’t have a Windows box near me right now.
Safari does nothing after you hit enter to run the code but the cookie is created, Firefox will show a page with the cookie info.
You can test it by using this code in the address bar;
- javascript:alert(document.cookie);
Look through the list you will see the cookie you just created, most likely at the end of the list if you did not go surfing after you created it.