Closed develorer closed 1 month ago
@develorer You should first navigate to a page that will set some cookies. I don't see that in your snippet.
Given the above, I suspect that I misunderstood the issue. Could you please explain in more details what cookies do you expect to see?
The user-data-dir's Default/Cookies
was populated manually, by launching the browser, and browsing without automation. I have tried to make that a little clearer in the initial post.
@develorer Thank you for more details. I think that to achieve interoperability, you should always run the browser with the --use-mock-keychain
flag. So, launch the browser with this flag manually to populate the user data dir, and then let Playwright reuse the same user data dir later, where it will add this flag automatically. Let me know whether this helps.
@dgozman thanks for your thoughts. That didn't work out on my end. However I found a workaround:
if I use --headless=new
instead of the playwright's default --headless
then it works fine and processes cookies correctly.
I am not sure why, but in any case I don't mind using the new headless mode. According to chromium's documentation, it is closer to the real thing. I am aware that it is slower, but you can't have everything in life 😉
Closing as per above, please feel free to open a new issue if this does not cover your use case.
Version
1.45.0
Steps to reproduce
Notice this prints an empty list. No cookies are set
Run the exact same script, but flip headless from
True
toFalse
Notice this prints a list full of cookies. Cookies are set
If I do not use
ignore_default_args=['--use-mock-keychain']
then cookies are never set, whether headless or notExpected behavior
I expect that cookies are set in headless mode.
Actual behavior
No cookies are set in headless mode, when a user_data_dir is specified.
Additional context
No response
Environment