in reply to Re^2: www::mechanize and www:mechanize::firefox
in thread www::mechanize and www:mechanize::firefox

I've log-in into the site using www::mechanize::firefox and that works well. I'm now trying to get the cookies after logging in but I get the error message 'Can't call method "declare" on an undefined value at /usr/local/share/perl/5.18.2/HTTP/Cookies/MozRepl.pm line 108' and I'm not sure why. Any ideas on where I'm going wrong here?

my $cookie_jar = HTTP::Cookies::MozRepl->new(); my $user_agent_name='Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:39.0) Ge +cko/20100101 Firefox/39.0'; my $agent = WWW::Mechanize->new( agent=>$user_agent_name, cookie_jar => $cookie_jar, autocheck => 1);

Replies are listed 'Best First'.
Re^4: www::mechanize and www:mechanize::firefox
by Corion (Patriarch) on Aug 08, 2015 at 14:12 UTC

    Where did you find the usage of passing in a cookie_jar parameter documented in WWW::Mechanize::Firefox? Reading the code actually helps. You're creating a cookie jar out of thin air and passing that to WWW::Mechanize.

    Hint: You're not supposed to create your own HTTP::Cookies::MozRepl, because they always live within the Firefox instance. You can retrieve the cookies from Firefox using $firefox->cookies().

    I'm not sure if it's possible to directly pass in all cookies to WWW::Mechanize. For sanitary and sanity reasons, I would only pass on the relevant cookies of the site you're automating, not all cookies.

Re^4: www::mechanize and www:mechanize::firefox
by shagbark (Acolyte) on Apr 02, 2016 at 06:21 UTC

    Yes. You haven't installed the extension mozrepl in your Firefox.

    However, although installing it will stop the crash, it won't load your cookies with the current Firefox. I have searched for hours, and not found any Perl module that can load either Chrome 49 or Firefox 45 cookies. (Chrome cookies now have their values encrypted.)

    I installed https://addons.mozilla.org/en-US/firefox/addon/cookie-exporter/, exported my Firefox cookies to cookies.txt, and tried reading that with the old HTTP::Cookies::Netscape->new(file => $CookieFile, autosave=>0). It doesn't work right off, because cookie-exporter doesn't write out the header indicating the file is a Netscape cookies file, so HTTP::Cookies::Netscape won't read it. (It's vital to use perl -w when trying HTTP::Cookies::Netscape, or else it won't tell you why it fails.)

    So, first add the line
    # Netscape HTTP Cookie File to the file, and then HTTP::Cookies::Netscape can read it.

    The correct documentation on the Netscape cookies file format does not appear to exist anymore, only documentation of the format of the individual lines. As a result, we have a new generation of tools that say they're using Netscape cookies format, but aren't.

    Alternately, you may have to just find the user's cookie sqlite db, open it via DBI, and query it for the cookies you want.