Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't exec javascript with zombie.js?

ok, I am a new learner to node.js: when I try to load google.com,and exec the script in the page,like this:

var zombie=require("zombie");
browser = new zombie.Browser({ debug: true })
browser.visit("http://www.google.com",function(err,_browser,status){
    if(err){
        throw(err.message);     
    }
})

but get error:

28 Feb 16:06:40 - The onerror handler

 on target 

{ frames: [ [Circular] ],
  contentWindow: [Circular],
  window: [Circular],
…………………………

what can I do?

like image 868
island205 Avatar asked Feb 28 '11 08:02

island205


1 Answers

The actual error message is hidden part way down the error output. Within the browser.visit function, add...

console.log(err.message);

...above throw(err.message);. This should give you a better indication of what's going wrong :)

EDIT: Having tested node 0.4.1 / zombie 0.9.1 on www.google.com, it looks like a javascript error (ILLEGAL TOKEN) is causing the problem. You can circumvent javascript errors by setting up your zombie code like so:

browser = new zombie.Browser();
browser.runScripts = false; // this disables executing javascript
browser.visit("http://www.google.com/", function (err, browser) {
  if (err) { console.log('Error:' + err.message); }
  else { console.log('Page loaded successfully'); }
  // ... rest of your code here
});

Personally, I don't find the current zombie error output very helpful, so I prefer to turn it off and display a simple console.log message when something goes wrong.

Lastly, you can also debug errors by passing in debug: true to the browser function:

browser = new zombie.Browser({ debug: true });

This will output all calls (inc. ajax) and might help to pinpoint the source of an error.

Good luck!

like image 91
6twenty Avatar answered Sep 29 '22 04:09

6twenty