saintex has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,
I know:
It is better to use WWW::Firefox , or WWW::Mechanize::Selenium... but I would like to have only a textual "mech", not a GUI, so I tried with WWW::Mechanize and SpiderMonkey.

So now I have these modules, those are working toegether in the finest way (thank you, Corion!):

SpiderMonkey (not a Perl module, but you know that...)
JavaScript.pm
WWW::Mechanize
WWW::Scripter::Plugin::JavaScript
WWW::Scripter::Plugin::JavaScript::Spidermonkey


And I'm able to process JavaScript in the way I want.
Also I can read from JavaScript a cookie value, that I set with PHP (or Perl).

But I'm not able to write a cookie with JavaScript and read it.
Writing with JavaScript fails in a silent way.

Any Idea how can I write cookies with Scripter::Plugin::JavaScript?
Is it some configuration problem?

use WWW::Scripter; use HTTP::Cookies::Netscape; my $cook= HTTP::Cookies::Netscape->new(file => 'ciao.txt' ,ignore_disc +ard => 1,autosave=>1); $m = new WWW::Scripter(autocheck=>1,cookie_jar=>$cook) ; $m->use_plugin(JavaScript => engine => 'SpiderMonkey' ); $m->get( 'http://mypage/provaw.php'); my $res=$m->response(); $m->cookie_jar->extract_cookies($res); $m->cookie_jar->save; my $cookie_content = $m->cookie_jar->as_string; print $cookie_content;
please, do you have any suggestions?
Thak you!

Replies are listed 'Best First'.
Re: WWW Mechanize and JavaScript Cookie
by Anonymous Monk on Mar 15, 2011 at 15:40 UTC
    Writing with JavaScript fails in a silent way.

    Turn on debugging

    Is it some configuration problem?

    Looks that way

      Thank you for your answer:

      >> Turn on debugging

      How can I enable?

      >> Looks that way

      I think it is already done, in my code I have:
      my $cook= HTTP::Cookies::Netscape->new(file => 'ciao.txt' ,ignore_disc +ard => 1,autosave=>1); $m = new WWW::Scripter(autocheck=>1,cookie_jar=>$cook) ;


      that is what you suggest to me... or I done some errors in the code?

        How can I enable?

        Ha ha, this is faq, see LWP::Debug

        FWIW, this works for me

        #!/usr/bin/perl -- use strict; use warnings; use WWW::Scripter; my $w = WWW::Scripter->new; $w->use_plugin('JavaScript'); #~ http://w3schools.com/jsref/prop_doc_cookie.asp# HTML DOM Document c +ookie Property #~ http://w3schools.com/jsref/tryit.asp?filename=tryjsref_doc_cookie #~ http://w3schools.com/jsref/tryit_view.asp?filename=tryjsref_doc_coo +kie $w->get('http://w3schools.com/jsref/tryit_view.asp?filename=tryjsref_d +oc_cookie'); print $w->cookie_jar->as_string, "\n\n"; print $w->document->body->as_text; __END__ Set-Cookie3: ASPSESSIONIDACRSCCCQ=FAKEASPSESSIONIDACRSCCCQ; path="/"; +domain=w3schools.com; path_spec; discard; version=0 Cookies associated with this document: ASPSESSIONIDACRSCCCQ=FAKEASPSESSIONIDACRSCCCQ