Corion / WWW-Mechanize-Chrome

automate the Chrome browser

Home Page:https://metacpan.org/release/WWW-Mechanize-Chrome

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cookie support not working

Rub3nCT opened this issue · comments

Is cookie support working? I tried ->set_cookie and ->load and both throw errors. The same code with HTTP::Cookies is working fine.

I'm I doing something wrong? Test code attached.
test.zip

Thank you for the report and the extensive tests!

Indeed, there was a coercion missing in ->set_cookie, where the secure argument did not get converted to a JSON::true or JSON::false value explicitly. I have now added this and will release this in version 0.45 soon.

The other part of your report tries to load a cookie jar from another cookie jar. The ->load() method only allows this for a file, and that is not implemented here. I have added the ->load_jar method, which allows you to import (or replace) a premade HTTP::Cookies cookie jar into Chrome.

I hope that is what you intended to do. I will also release this in 0.45 soonish.

Thanks! I just installed current code and all test passed successfully.

->set_cookie is working great, but ->load_jar throws:

Can't locate object method "scan" via package "CookiesNew" (perhaps you forgot to load "CookiesNew"?) at C:/Strawberry/perl/site/lib/HTTP/Cookies/ChromeDevTools.pm line 148.

What I would like to do is to 'import' my current Chrome cookies into my ChromeDevTools session, so I don't have to login every time I use it.

  1. Get Cookies from Chrome directory.
  2. Load jar with HTTP::Cookies::Chrome.
  3. Save jar with HTTP::Cookies format.
  4. Import cookies from saved jar to HTTP::Cookies::ChromeDevTools with ->load_jar so I can use them in WWW::Mechanize::Chrome.

An error is also thrown in HTTP::Cookies::Chrome when saving jar:

DBD::SQLite::st execute failed: datatype mismatch at C:/Strawberry/perl/site/lib/HTTP/Cookies/Chrome.pm line 240.

It would be great to have such option built-in in WWW::Mechanize::Chrome or HTTP::Cookies::ChromeDevTools.

Anyway, I think I can make what I want to achieve following this steps:

  1. Load my Chrome cookies with HTTP::Cookies::Chrome.
  2. Extract needed values from the hash of HTTP::Cookies::Chrome.
  3. Then use ->set_cookie to set them in my WWW::Mechanize::Chrome session.

Neither ->load() nor ->load_jar take a filename (CookiesNew in your case) as an argument. ->load_jar() wants a premade HTTP::Cookies object, like HTTP::Cookies::Chrome. But your idea of saving the cookies you want is a good one. I think loading a HTTP::Cookies file is very simple now that I wrote ->load_jar() - in fact, ->load() should now simply work with the filename.

Thanks again for your code that demonstrated the problem very well!

Released as 0.46