yt-dlp: `--cookies-from-browser` errors when Chrome/chromium-based browser is open in Windows
DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE
- I understand that I will be blocked if I intentionally remove or skip any mandatory* field
Checklist
- I’m reporting a bug unrelated to a specific site
- I’ve verified that I’m running yt-dlp version 2023.03.04 (update instructions) or later (specify commit)
- I’ve checked that all provided URLs are playable in a browser with the same IP and same login details
- I’ve checked that all URLs and arguments with special characters are properly quoted or escaped
- I’ve searched known issues and the bugtracker for similar issues including closed ones. DO NOT post duplicates
- I’ve read the guidelines for opening an issue
Provide a description that is worded well enough to be understood
cannot extract cookies from chrome when the chrome browser is open and after closing all the windows of chrome, it can run correctly i have no idea what is going wrong
Provide verbose output that clearly demonstrates the problem
- Run your yt-dlp command with -vU flag added (
yt-dlp -vU <your command line>) - If using API, add
'verbose': TruetoYoutubeDLparams instead - Copy the WHOLE output (starting with
[debug] Command-line config) and insert it below
Complete Verbose Output
C:\Users\Mechrevo>yt-dlp.exe -vU --newline -R 30 --proxy socks5://127.0.0.1:7890 -i -o "Z:\YouTube\%(upload_date)s %(title)s.%(ext)s" --ignore-config --hls-prefer-native --add-metadata --embed-thumbnail --sub-langs all,-live_chat,-danmaku,-jpn-JP --embed-subs --merge-output-format mp4 --live-from-start --cookies-from-browser chrome "https://www.youtube.com/watch?v=3DiKrPSmO5c"
[debug] Command-line config: ['-vU', '--newline', '-R', '30', '--proxy', 'socks5://127.0.0.1:7890', '-i', '-o', 'Z:\\YouTube\\%(upload_date)s %(title)s.%(ext)s', '--ignore-config', '--hls-prefer-native', '--add-metadata', '--embed-thumbnail', '--sub-langs', 'all,-live_chat,-danmaku,-jpn-JP', '--embed-subs', '--merge-output-format', 'mp4', '--live-from-start', '--cookies-from-browser', 'chrome', 'https://www.youtube.com/watch?v=3DiKrPSmO5c']
[debug] Encodings: locale cp936, fs utf-8, pref cp936, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version stable@2023.03.04 [392389b7d] (win_exe)
[debug] Python 3.8.10 (CPython AMD64 64bit) - Windows-10-10.0.19045-SP0 (OpenSSL 1.1.1k 25 Mar 2021)
[debug] exe versions: ffmpeg 4.4-full_build-www.gyan.dev (setts), ffprobe 4.4-full_build-www.gyan.dev
[debug] Optional libraries: Cryptodome-3.17, brotli-1.0.9, certifi-2022.12.07, mutagen-1.46.0, sqlite3-2.6.0, websockets-10.4
[Cookies] Extracting cookies from chrome
[debug] Extracting cookies from: "C:\Users\Mechrevo\AppData\Local\Google\Chrome\User Data\Default\Network\Cookies"
[debug] Found local state file at "C:\Users\Mechrevo\AppData\Local\Google\Chrome\User Data\Local State" Traceback (most recent call last):
File "yt_dlp\__main__.py", line 17, in <module>
File "yt_dlp\__init__.py", line 967, in main
File "yt_dlp\__init__.py", line 927, in _real_main
File "yt_dlp\YoutubeDL.py", line 652, in __init__
File "yt_dlp\YoutubeDL.py", line 3827, in print_debug_header
File "yt_dlp\YoutubeDL.py", line 3871, in _setup_opener
File "yt_dlp\cookies.py", line 99, in load_cookies
File "yt_dlp\cookies.py", line 120, in extract_cookies_from_browser
File "yt_dlp\cookies.py", line 289, in _extract_chrome_cookies
File "yt_dlp\cookies.py", line 952, in _open_database_copy
File "shutil.py", line 418, in copy
File "shutil.py", line 264, in copyfile
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\Mechrevo\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\Network\\Cookies'
[25380] Failed to execute script '__main__' due to unhandled exception!
C:\Users\Mechrevo>
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 53
- Comments: 90 (24 by maintainers)
Links to this issue
Commits related to this issue
- Use shadow copy to extract cookies when chrome is open Fixes #7271 — committed to csm10495/yt-dlp by csm10495 3 years ago
- 3.44 - cookie extraction from edge and chrome ; Fixed errors with information display added opening an instance with unblocked cookies for edge and chrome: --disable-features=LockProfileCookieDataba... — committed to pagend0s/pobierak4windows by pagend0s 3 years ago
(edited to be useful)
This issue affects Windows versions of Chrome and some other chromium-based browsers such as Edge.
Possible workarounds are:
Try after closing chrome completely OR
Launch
chrome.exewith the flag:--disable-features=LockProfileCookieDatabaseFor convenience, you can add it your desktop shortcut for Chrome. Right-click the shortcut, go into Properties, and change the executable path, e.g.:
"C:\Program Files\Chrome\chrome.exe" --disable-features=LockProfileCookieDatabaseAlternatively, you can install the ChomeCookieUnlock yt-dlp plugin
As a temporary workaround, run
chrome.exewith:–disable-features=LockProfileCookieDatabase
Expect this flag to go away after a few more releases of Chrome.
Hi everyone,
I noticed there’s ongoing interest in making it easier to export cookies for use with
yt-dlp, especially for users who may not want to use complex tools or scripts. To help with this, I’ve created a Tampermonkey UserScript that lets users easily export cookies from the current site (like YouTube) in the Netscape format, ready to be used withyt-dlp.The script runs directly in the browser, collects the cookies using
document.cookie, and converts them into the required format. It generates a.txtfile for download, which can then be passed toyt-dlpusing the--cookiesoption. This eliminates the need for manual copying or Node.js scripts, making it beginner-friendly.Here’s how it works:
.txtfile withyt-dlp:I believe this UserScript can help users who may not be comfortable with tools like
EditThisCookieor manual Node.js scripts. It works entirely in the browser, requires no external dependencies, and is ready to use withyt-dlp.Let me know if this is something that could be useful to the community, and I’m happy to contribute more!
That’s kind of offensive tbh. I was just providing a possible solution. This is open source code, people make recommendations, code changes, etc. it’s part of the culture.
I’m not sure why my suggestion would not instill confidence. I’m offended by that remark. It makes me think I shouldn’t share things that I think can help steer us towards a solution. I had been very excited to share that because it gives the possibility of fixing the issue for folks longer term.
Honestly it’s not a suggestion for someone who doesn’t know python. It’s a suggestion to other people at least somewhat familiar with parts of the yt-dlp source code.
I’m not sure why you then say it shouldn’t need to exist. None of us influenced the chromium behavior change here. We are where we are: trying to provide solutions.
Anyways, you don’t need
--cookies-from-browser. You can download the cookies.txt file then just pass those cookies via--cookies. Consider something like https://github.com/kairi003/Get-cookies.txt-LOCALLY to get that file.re: https://github.com/seproDev/yt-dlp-ChromeCookieUnlock/
Here is an example to help novice users quickly use the plug-in to solve this problem. You don’t have to use anything from this example, you just need to store the corresponding files in the corresponding directory. 这是一个例子,方便新手用户快速使用插件解决这个问题。你不必使用这个例子上的任何东西,你只需要按照响应的目录存放对应文件即可。
I don’t have a solution but I have done some research that may be useful.
LockProfileCookieDatabasefeature results inSQLitePersistentCookieStore::enable_exclusive_accessbeing set?exclusive=truebeing added to the file URI passed to sqlite on Windows only sourceEXCLUSIVE locksection ofwinLock()I tried moving the Cookies database and creating a symlink and hardlink to it for chrome to use but
LockFileExfollows the links. It’s possible that if the database is placed on a filesystem that doesn’t support locking (like an old version of samba) then the locking won’t take effect but that isn’t a very practical solution.the shadow copy approach seems like a good way around the limitation on the yt-dlp side. I think admin will be required for any solution which makes many options available but most would be too invasive. One idea I had would be to create a separate tool that a user could use to start chrome and inject a DLL that makes
LockFileExdo nothing.The good news is that I don’t think Linux will be affected because mandatory locking with fcntl is opt-in and disabled by default source (see Mandatory locking section). WSL should also be unaffected because
LockFileExhopefully can’t be supported in WSLI adapted the work of @csm10495 in to a yt-dlp plugin: https://github.com/seproDev/yt-dlp-ChromeCookieUnlock
Seems to be working well for me. Use at your own risk.
I found the chromium commit-https://chromium.googlesource.com/chromium/src/+/03c1544d31014c04caace4145676c30586bd9612
And I guess I spoke too soon-ish. This project: https://github.com/thewh1teagle/rookie came up with a way to do it without admin. It cheats a bit, it actually kills the process in chrome that holds the lock to the file… thus releasing the lock… but hey chrome, just restarts it when needed and it works out fine.
I’ve replicated it in a pure-python gist here: https://gist.github.com/csm10495/e89e660ffee0030e8ef410b793ad6a7e… using that logic cookies can be fetched even while Chrome is running, without admin.
I can’t reproduce
I was shown following error:
ERROR: Could not copy Chrome cookie database. See https://github.com/yt-dlp/yt-dlp/issues/7271 for more infoAnd I was able to resolve it by simply closing Chrome (because it locks the cookies file).In case it helps someone unfamiliar with plugins as I was, you can simply clone into the configuration directory like so (Windows example):
Now I’m just trying to find a way to get rid of the
Attempting to unlock cookiesmessage so I can pipe the output of the following command directly to a JSON field extractor:Not sure what we can really do if this is an intentional change to chromium (which could trickle downstream to Brave et al). We can’t tell people to downgrade their browsers.
Firefox for all?
(another small point: Also it works fine for all browsers on Linux or Mac, only Windows is affected)
Up! Today noticed that yt-dlp doesn’t read cookies from browser, when browser is open. yt-dlp v.2023.07.06 edge v.117.0.2045.31
@ForsakenRei for that use case you may want to use
yt-dlp --cookies-from-browser <mybrowser> --cookies cookies.txt(no other arguments) (while the browser is closed if you are on windows) which will cause yt-dlp to write out the cookies to that text file, then you can use that file as your cookie storage withyt-dlp --cookies cookies.txt ...(but be aware of the security implications of having your cookies lying around in a text file and be careful where you put it)
For some reason, not sure if related but the --disable-features=LockProfileCookieDatabase seemed to slow down and cause my chrome to hog more memory. Might be a no brainer, but worked better than the Chrome solution for me is to just get them from Firefox instead.
–cookies-from-browser firefox
Maybe it is of interest, but the official Microsoft Bing Wallpaper app ran into similar issues and they updated the Bing Wallpaper app to adapt to the changes in Chromium/Edge (enablement of LockProfileCookieDatabase), see: https://twitter.com/ericlaw/status/1719368738514882581
I have switched to firefox, so much easier and no issues with decrypting cookies:
yt-dlp --cookies-from-browser firefox:~/snap/firefox/common/.mozilla/firefox/ ...I’ve closed the PR for shadow copying to prevent it getting more stale. In the future if the team wants, i’ve moved the shadow copy functionality to https://github.com/csm10495/shadowcopy. They can import it and shadow copy, etc.
Opened a PR to allow this to work at least when the user is admin via a shadow copy. (https://github.com/yt-dlp/yt-dlp/pull/7290)
Any news on this? Still a bit confusing to find out what the state here is now.
If I understand this correctly - and please correct me if I am wrong - this issue cannot be solved for current and future Chrome (and Chrome derivates?) versions on Windows due to how these “safety” features are implemented on this platform.
Should this be the case, I believe that this should be communicated more clearly and more prominently - like on the main README.md etc.
And maybe this issue should be closed as WONTFIX?
I figured out that due to changes in puppeteer, using the Chrome data of it won’t work with yt-dlp, using an old version (v23.2.1 for example) did work for me.
( I know this isn’t well related to yt-dlp, but as it’s not an issue of the project itself, I think it’s better to tell anyone regarding this )
1 and 2. Haven’t worked for me for some months. 3. Doesn’t work for me either.
In the end I had to use Firefox cookies.
now edit your reply with correct link
If you suspect your computer had been compromised, just invalidade the cookie(s) by logging out of the respective accounts. Easy to do. When you log in again, it will generate new cookies.
mbway is saying that yt-dlp should do this, so that users are immediately made aware of the potential issue and the workaround.
Works fine with non-chromium browsers
This is the plan
Does not work for me. I run this:
C:\Users\Shadow>yt-dlp.exe --cookies-from-browser chrome -f 599 “https://www.youtube.com/watch?v=_XhEFW1Zmew” Extracting cookies from chrome ERROR: Could not copy Chrome cookie database. See https://github.com/yt-dlp/yt-dlp/issues/7271 for more info ERROR: Could not copy Chrome cookie database. See https://github.com/yt-dlp/yt-dlp/issues/7271 for more info
Given the sensitive nature of cookies, having a user-script such as the one above that is easy to audit may be preferable to a browser extension for some people. (It requires tamper monkey but that is more trustworthy than a more niche cookie-focused extension)
It’s possible to obtain the crx of an extension and un-minify to audit an extension but this is more challenging. One of the reasons I created
--cookies-from-browserwas to give users an option they can easily audit or trust as it comes from yt-dlp itself.@Heretic-tripto the script is a bit off topic for this issue though and would have been better as a new discussion
By canceling the license and joining your script to yt-dlp you will help millions of people. Are you offended by something or what are the reasons for restricting everyone? It’s much more difficult for people to install a plugin. And now you are making their life difficult. For what? You don’t even get paid for this code. You look stupid limiting the development of a project that has helped you a million times. Sorry.
@ofek https://github.com/seproDev/yt-dlp-ChromeCookieUnlock/pull/1
then after PR is merged you can:
I’m a big fan of yt-dlp, but sorry, I believe in attribution for my external open source code. The unlicence isn’t really something I’m currently interested in. Thanks for considering it.
@csm10495 Would you be willing to Unlicense your script so we can merge it?
What’s the point of such security? Clowns from chrome never disappoint
我也遇到了这个情况,目前找不到解决方案 我使用的是Windows11和edge浏览器 有人知道如何解决请帮助我
Thank you. Yeah it’s quite dangerous to put my cookies as a plain file even though I only extracted cookies for YouTube, hopefully we will have a better solution later.