With the file
jello.jshello.js
var leg = {
aa: "Hello from javascript"
}
function to_json() {
return JSON.stringify(leg);
}
And the file perl.pl
use strict;
use warnings;
use WWW::Mechanize::PhantomJS;
my $js = WWW::Mechanize::PhantomJS->new(launch_exe=> 'C:/prog/phantomj
+s/bin/phantomjs.exe');
$js->get_local("hello.js");
#$js->update_html('<script src="hello.js" type="text/javascript"></scr
+ipt>');
#print $js->content;
#my ($val, $type) = $js->eval_in_page('JSON.stringify(window.leg);');
my ($val, $type) = $js->eval_in_page('to_json()');
print "val: $val, type: $type\n";
I can't have any meaningfull result from calling
eval_in_page either on the
leg var directly or via the function.
Can you show me how to have this working ?
Thanks
Update without phantomjs
use strict;
use warnings;
use Log::Log4perl qw(:easy);
Log::Log4perl->easy_init($ERROR);
use WWW::Mechanize::Chrome;
my $js = WWW::Mechanize::Chrome->new(report_js_errors=>1);
$js->get_local("hello.js");
#$js->update_html('<script src="hello.js" type="text/javascript"></scr
+ipt>');
#print $js->content;
#my ($val, $type) = $js->eval_in_page('JSON.stringify(window.leg);');
my ($val, $type) = $js->eval_in_page('to_json()');
print "val: $val, type: $type\n";
This gives undef for $val whatever I'm calling: the to_json() function or JSON.stringify directly.