Search code examples
cookiesgreasemonkeytampermonkeyuserscripts

Is it possible to swap user cookies/profiles with Tamper/Greasemonkey?


The chrome "swap my cookies" extension allows you to swap between multiple 'profiles' in chrome, that span all sites.

I'm attempting to create something similar for testing my own web services, so I'd like to restrict it to only my domains.

What would be convenient, is to be able to do this from a small userscript using tampermonkey or greasemonkey to add a menu that would swap cookies etc.

Does anyone have any idea on how to get started? Or if it's at all possible?


Solution

  • If your cookies are not httponly you can load them with document.cookie, save them with GM_setValue('cookie_profile_a',document.cookie) and GM_getValue('cookie_profile_a') or in the localStorage with localStorage.setItem('cookie_profile_b',document.cookie) and localStorage.getItem('cookie_profile_b'). For creating a menu in Tampermonkey you can use existing solutions like GM_config (https://stackoverflow.com/a/14594346#43462416).