console.log from page.evaluate?

1,972 views
Skip to first unread message

Milian Wolff

unread,
May 3, 2012, 7:01:27 AM5/3/12
to phan...@googlegroups.com
Hey all,

I must be missing something... Why is this not working for me:

var page = require('webpage').create();

page.open('http://google.de', function(s) {
  console.log(s);
  var i = page.evaluate(function(j){
    console.log(j);
    return j;
  }, 5);
  console.log("test", i);
  phantom.exit();
});

I get:
success
test 5

instead of:
success
5
test 5

Looking at e.g. the weather.js example (which needs to pass the address to the .evaluate function btw, I'll fix that), it uses console.log and it just works... So what am I doing wrong?

dtkirby

unread,
May 3, 2012, 9:59:34 AM5/3/12
to phan...@googlegroups.com
Set up your onConsoleMessage callback (outside the 'evaluate' block):

page.onConsoleMessage = function (msg){
    console.log(msg);    
};  

Milian Wolff

unread,
May 3, 2012, 10:00:37 AM5/3/12
to phan...@googlegroups.com
ok thanks - I've missed that in the weather example. But shouldn't that be the default?

Bye

James Greene

unread,
Jul 19, 2012, 3:48:11 PM7/19/12
to phan...@googlegroups.com
Personally, I would definitely NOT want that to be the default behavior.

Prahlad Yeri

unread,
Jun 28, 2014, 2:53:30 PM6/28/14
to phan...@googlegroups.com
Thanks! This helped me.
Reply all
Reply to author
Forward
0 new messages