New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
userDataDir + headless = lost authorization #921
Comments
I can duplicate this on MacOS 10.10.5 using 0.11.0 and facebook. I'm also having trouble with an internal site I'm trying to automate, but also seeing it in headful mode. I only mention it here because of the note about 'response.request().headers' not containing cookies. |
Headless isn't closing gracefully, which sometimes causes data loss when Chrome closes before it finishes writing things to disk. See https://crbug.com/771830 References #921
Hello, |
For the record: upstream bug is filed as https://crbug.com/771830 |
@aslushnikov Is it connected? In OP's case, two first runs are with Did you mean #918 ? |
The chromium can't save and restore storage and cookies in headless mode. It's chromium bug. |
It's chromium bug. It's not puppeteer bug. run some times, you can find the cookie is different in every times(same userDataDir) |
This is actually not fixed by #1028. |
Refs: #1055 (comment) |
This should be fixed as of #1063. @vsemozhetbyt can you confirm? Thanks |
@JoelEinbinder Unfortunately, exactly this case from OP still is not fixed: logging in in headful mode is not restored in headless mode. I did not test if cookies are stored and restored in completely headless mode — this can be fixed, but for me, this is rather a speculative use case. |
For the record: this is tracked by upstream bug https://bugs.chromium.org/p/chromium/issues/detail?id=775703 |
This roll brings in a bunch of important patches: - crrev.com/512647 Changed headless browser profile dir to use Default profile path - crrev.com/512760 DevTools: stop idleness detector when pending navigation commits - crrev.com/512905 DevTools: introduce Page.getFrameTree - crrev.com/513373 DevTools: report loaderId in the lifecycle events - crrev.com/513419 DevTools: introduce Page.setLifecycleEventsEnabled - crrev.com/513422 DevTools: return loaderId from Page.navigate Fixes #921 BREAKING CHANGE: Headless user profile structure is changing. Custom profiles set with --user-data-dir flag will no longer be read in Chrome 63 and will have to be recreated. Alternatively, you can migrate old headless profile to a new structure. if you stored your profile in `<profile>` folder, you would run the following bash commands: ```bash cd <profile> mkdir Default mv * Default ``` Full headless-dev PSA announcement: https://groups.google.com/a/chromium.org/forum/#!msg/headless-dev/asX8WgktXIE/zTUfmHDcAQAJ
@aslushnikov @JoelEinbinder Unfortunately, #1259 does not fix the case in the OP: the outputs of the examples still differ and the |
@vsemozhetbyt we're very sorry; it indeed doesn't work! We're on it. |
For the record: upstream patch is up for review https://chromium-review.googlesource.com/c/chromium/src/+/752743 |
This test ensures that Chrome Headless can successfully read cookies written by Chrome Headful. References puppeteer#921
This test ensures that Chrome Headless can successfully read cookies written by Chrome Headful. References #921
I'm also seeing this issue on Windows 10. Cookies aren't persisted when running in headless mode since v2.1.0. It worked fine in v2.0.0. The issue is not present on macOS, version v2.1.1 and v3.0.2 work as expected on the mac. The fix suggested by @Ron-Burg to set the user data dir as an argument does not work for me either. On thing I noticed is that when running in headless mode true the Cookies table in the Cookies file (SQLite database) stays empty. When running with headless mode false the Cookies table does get populated. |
Tried every suggestion here. Can't get cookies to persist from headless to headful. Even between headless sessions, the cookies are lost. |
So the solution is to revert to |
I've downgraded puppeteer from v3.0.4 to v2.1.1 which didn't work and then finally downgraded to v2.0.0 and cache is now working properly in headless mode. |
why is this closed? |
Is this issue really fixed in Chrome version Tried in Windows 10. userDataDir with headless doesn't store my login session. |
I'm adding this for reference as a few people have mentioned macOS in this thread: I've been able to use cookies for a couple of years without issue in puppeteer using the |
workaround? (not cookies but whole user profile, including localstorage) |
Hi, I had this problem about 1 year and a half ago and I submitted a comment in this thread. The same problem was happening to me a month ago and the solution I found was including the full path in the Example:
|
Hello guys. Still face this on Chrome 85.0.4183.121 (Official Build) (64-bit) for Windows 10. |
Is this issue solved or still pending? Because, it's still happening on v5.4.0 |
I just use playwright and there is no such issue + playwright is maintained by original authors. This issue will probably never be fixed because I don't see same progress in puppeteer as it used to be. |
I can't believe This issue is still persisting since 2017 and it is almost 2021 :/ |
This is not a "bug" really. The only way to fix that is by recompiling chromium, this is not a puppeteer issue, you can easily reproduce this behavior by running the chromium/chrome command line passing --user-data-dir and --headless to confirm that when --headless is present the user-data-dir will be ignored and the sessions will not be retrieved. This is by design... |
and this is a very lame design I must say |
Exactly... as a malicious software developer, for me this does not represent a limitation since I can bypass it perfoming some runtime tricks on the targeted software. But for those legit users who don't have the ($) time and motivation necessary to get through this, it is just lame design, as you say. In the end they are blocking the legit users while the malicious developers are still taking full advantage from the debugging tools 👍 If anyone here reading this is using chromium to defeat captcha on botnets: yay! If you are not but you would like to you just have to think about one thing: The behavior of chromium-like browsers is completely different when --headless is enabled. So think carefully about it, all you really want is to do everything without the (victim) (client) user seeing anything. You don't need headless... Keep your software away from this option and you will be fine. |
So any solution for the C# bindings? Except using firefox instead? :p |
@H4xX0r1337 the solution is use playwright. it works and is much better documented |
@mikelpr yea people complaining here are too lazy to even switch package. Just use playwright and be happy? It has even python, c# bindings etc. |
@mikelpr @shirshak55 ayy thanks, that that looks very cool as well. It also looks more modern and the async API would be another pro. Although it is much less known than selenium. |
Olá, estamos em 2022, não sei se foi resolvido de outra forma. Mas resolvi usando a biblioteca puppeteer-firefox: //npm i puppeteer-firefox const puppeteerFirefox = require('puppeteer-firefox'); let browser = await puppeteerFirefox.launch({ Depois setei: Até mais... |
test-profile-dir
:You will see something like this:
Sign in into Twitter and close the browser.
await browser.close();
can be uncommented). You will see something like this:headless: true,
The output is the same as before authorization:I have tried various sites, all of them seem to lose authorization in headless mode.
Some more notes:
response.request().headers
does not contain cookies in bothheadless: false
andheadless: true
modes.console.log(await page.cookies('https://twitter.com/'));
contains many cookies in theheadless: false
mode. In theheadless: true
mode it gives an empty array[]
.The text was updated successfully, but these errors were encountered: