最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

node.js - can't exec javascript with zombie.js? - Stack Overflow

programmeradmin1浏览0评论

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

var zombie=require("zombie");
browser = new zombie.Browser({ debug: true })
browser.visit("",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?

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

var zombie=require("zombie");
browser = new zombie.Browser({ debug: true })
browser.visit("http://www.google.",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?

Share Improve this question edited Feb 28, 2011 at 8:21 Joachim Sauer 308k59 gold badges566 silver badges622 bronze badges asked Feb 28, 2011 at 8:16 island205island205 1,74017 silver badges28 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

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., 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./", 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!

发布评论

评论列表(0)

  1. 暂无评论