sgentle/phantomjs-node — Issue #3: problem with page.onConsoleMessage
Author: sirLisko
Created: 2011-11-15 12:02:43+00:00
State: open

Hello,

I was trying to convert a script that I'm using in "pure" phantom js and I'm having some problem with the console.log inside the page.evaluate. I'm using page.onConsoleMessage, as described in the phantomjs API.

I've tried a lot of different solutions but it looks like impossible to figure out this problem.

This is my code:

```javascript
var phantom = require('phantom');

phantom.create(function(ph) {
return ph.createPage(function(page) {
page.onConsoleMessage = function (msg) { console.log(msg); };
return page.open("http://www.google.com", function(status) {
if (status !== 'success') {
console.log('Unable to access network');
} else {
return page.evaluate((function() {
console.log('foo');
return document.title;
}), function(result) {
console.log('Page title is ' + result);
return ph.exit();
});
}
});
});
});
```

In addiction I was also trying to pass some parameters inside the page evaluate but if I tried to pass something node give me a referenceError as document is not defined.