Can't execute javascript with zombie.js?

ok, I'm a new student of node.js: when I try to download google.com, and execute the script on the page, for example:

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 the error:

 28 Feb 16:06:40 - The onerror handler on target { frames: [ [Circular] ], contentWindow: [Circular], window: [Circular], ………………………… 

What can I do?

+4
source share
1 answer

The actual error message is partially hidden down the error output. In the browser.visit function add ...

 console.log(err.message); 

... higher throw(err.message); . This should give you a better idea of ​​what is going wrong :)

EDIT: by testing node 0.4.1 / zombie 0.9.1 at www.google.com, it looks like a JavaScript error (ILLEGAL TOKEN) is causing the problem. You can get around JavaScript errors by customizing your zombie code as follows:

 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 do not find the current zombie error error very useful, so I prefer to disable it and display a simple console.log message when something goes wrong.

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

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

This will output all calls (incl. Ajax) and may help determine the source of the error.

Good luck

+7
source

Source: https://habr.com/ru/post/1341608/


All Articles