Moustachauve / cookie-editor

A powerful browser extension to create, edit and delete cookies
https://cookie-editor.com/
GNU General Public License v3.0
721 stars 148 forks source link

Feature Request: Support cookies output format from Chrome DevTools Storage.getCookies #186

Open anasfanani opened 6 months ago

anasfanani commented 6 months ago

When using automation task in selenium, I can get all browser cookies with this python command:

all_cookie = driver.execute_cdp_cmd('Storage.getCookies',{})

And this for set the cookie :

driver.execute_cdp_cmd('Network.enable', {})
driver.execute_cdp_cmd('Network.setCookie', cookie)
driver.execute_cdp_cmd('Network.disable', {})

Output Example is:

[
{
        "domain": ".so.sites.com",
        "expires": 1747602543,
        "httpOnly": false,
        "name": "bcap",
        "path": "/",
        "priority": "Medium",
        "sameParty": false,
        "sameSite": "unspecified",
        "secure": true,
        "session": false,
        "size": 6,
        "sourcePort": 443,
        "sourceScheme": "Secure",
        "value": "0"
    }
]

The structure of cookies is described here : https://chromedevtools.github.io/devtools-protocol/tot/Network/#type-Cookie

This would be verry usefull.

Currently I'm use this code to export:

def exportCookie(cookies):
        output = []
        for cookie in cookies:
            cookie_dict = {}
            cookie_dict['domain'] = cookie.get('domain')
            if cookie.get('expires') != -1:
                cookie_dict['expirationDate'] = cookie.get('expires')
            cookie_dict['hostOnly'] = not cookie.get('domain', '').startswith('.')
            cookie_dict['httpOnly'] = cookie.get('httpOnly')
            cookie_dict['name'] = cookie.get('name')
            cookie_dict['path'] = cookie.get('path')
            sameSite = cookie.get('sameSite')
            if sameSite is None or sameSite == 'unspecified' or sameSite == 'None':
                cookie_dict['sameSite'] = 'no_restriction'
            else:
                cookie_dict['sameSite'] = sameSite.lower()
            cookie_dict['secure'] = cookie.get('secure')
            cookie_dict['session'] = cookie.get('session')
            cookie_dict['storeId'] = None
            cookie_dict['value'] = cookie.get('value')
            output.append(cookie_dict)
        output = json.dumps(output, indent=4)
        return output

Update, I'm suprissed when try to export with many domain, can't set the cookies, the permission is for all site, but only opened tab can set the cookies.