-1

There is a library in python browsercookie that allows the user to get cookies stored in the browser and read their data. I am looking for a way I can edit the cookie data and then put it back in the browser files. I cant get to do this using browsercookie. Is there any way or am I missing something here?

A cookie can be edited manually in Chrome as written here: https://thisinterestsme.com/modifying-cookies-developer-tools/

This question gives insight on how to get the data: How to get cookies from web-browser with Python?

SideNote: What I actually want is to get windows username and save it into my website's cookie so when the user opens the website after running this code it will have its username there on the website. (This is not part of the question)

Ammar H Sufyan
  • 97
  • 1
  • 3
  • 13
  • I doubt that you can change cookies while the browser is running. Once it loads the cookie into memory, it won't notice changes your application makes to the file. – Barmar Jun 21 '19 at 23:40
  • The browser wont be running while this code is running. The user is supposed to run the code that will update the cookies in the hard disk before opening the browser. – Ammar H Sufyan Jun 21 '19 at 23:43
  • I edited the question to make it more clear – Ammar H Sufyan Jun 21 '19 at 23:44
  • The `browsercookie` library as it currently exists is only for reading cookies, not writing them. You could attempt to reverse-engineer this but there's nothing to stop Mozilla or Google from changing the format that they store cookies. – Joe Aug 04 '19 at 13:52

1 Answers1

0

I got successful with writing a cookie into the browser the following way:

  1. Get the SQLite database the Chrome saves its cookies in from: C:\Users\%username%\AppData\Local\Google\Chrome\User Data\Default\Cookies

  2. Place the cookie content in "value", and set "encrypted_value" to NULL and "priority" to 0

Ammar H Sufyan
  • 97
  • 1
  • 3
  • 13