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.
When using automation task in selenium, I can get all browser cookies with this python command:
And this for set the cookie :
Output Example is:
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:
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.