thewh1teagle / rookie

Load cookies from your web browsers
https://crates.io/crates/rookie
MIT License
200 stars 17 forks source link

[Bug]: Reading Chrome cookies in Windows causes recent changes to cookies to be lost #47

Open FeldrinH opened 2 months ago

FeldrinH commented 2 months ago

What happened?

If you set a cookie in Chrome and then read cookies using rookie then the recently set cookie is not found by rookie. Reloading the page in Chrome, the cookie has reverted to its previous value (or disappeared if it was previously not set).

Steps to reproduce

  1. Go to https://setcookie.net/ in Chrome.
  2. Set a random cookie.
  3. Reload the page and check that the cookie is set.
  4. Without closing the browser, call rookiepy.chrome().
  5. Observe that the returned list of cookies does not contain the cookie set in step 2.
  6. Reload https://setcookie.net/ and observe that the recently set cookie has disappeared.

Tested on Windows 10 with Chrome 128.0.6613.114 and rookiepy 0.5.2.

What browsers are you seeing the problem on?

Chrome

Relevant log output

No response

thewh1teagle commented 2 months ago

Thanks for report! What if you try it with admin rights? (open cmd as admin and then use rookiepy) It should then extract it in better way

FeldrinH commented 2 months ago

What if you try it with admin rights? (open cmd as admin and then use rookiepy) It should then extract it in better way

That does improve things. With admin rights it does not revert cookies to the previous value in Chrome, but rookiepy.chrome() still returns the old value for recently set cookies (experimentally, it takes about 30 seconds from setting a cookie to having rookiepy.chrome() return the new value).

FeldrinH commented 2 months ago

If you wait about 30 seconds without admin rights then rookiepy.chrome() also returns the new value and does not revert. Presumably this means that Chrome waits about 30 seconds before flushing changes to the cookie database to disk.

EDIT: Found confirmation of this in Chromium source code: https://github.com/chromium/chromium/blob/main/net/extras/sqlite/sqlite_persistent_cookie_store.cc#L332-L335. Apparently the 30 second delay to flush has been in Chrome for a long time (12+ years).