How to debug a PhantomJS script? -


my script has syntax error instead of showing error, phantomjs doesn't display anything. why phantom js isn't showing parse error if script has errors?

in following phantomjs script (running via windows cmd), phantomjs hangs instead of showing error if there parsing error in script.

var system = require('system'); var webpage = require('webpage').create();  console.log('starting script');  if (system.args.length === 0) {     console.log('no args'); } else {     system.args.foreach(function(arg,index){         console.log('arg '+arg+' @ '+index);     }); }  webpage.open('http://localhost:3000/cookie-demo',function(status){     if (status === 'success'){         console.log('success in opening page');         phantom.cookies.foreach(function(cookie,index){             ( var key in cookie){ 

/*if instead of index, use variable (undefined), script hangs!*/

console.log('[cookie:'+index+']'+key+'='+'cookie[key]');         }     });     phantom.exit(0); } else{     console.log('could not open page');     phantom.exit(1); } 

});

if there no syntax error in script, following output

c:\users\manu\documents\manu\programs\random>phantomjs --cookies-file=cookie-jar.txt phantomtest.js starting script arg phantomtest.js @ 0 success in opening page [cookie:0]domain=cookie[key] [cookie:0]expires=cookie[key] [cookie:0]expiry=cookie[key] [cookie:0]httponly=cookie[key] [cookie:0]name=cookie[key] [cookie:0]path=cookie[key] [cookie:0]secure=cookie[key] [cookie:0]value=cookie[key] [cookie:1]domain=cookie[key] [cookie:1]expires=cookie[key] [cookie:1]expiry=cookie[key] [cookie:1]httponly=cookie[key] [cookie:1]name=cookie[key] [cookie:1]path=cookie[key] [cookie:1]secure=cookie[key] [cookie:1]value=cookie[key] 

but if there syntax error, see nothing on console , doesnt exit

c:\users\manu\documents\manu\programs\random>phantomjs --cookies-file=cookie-jar.txt phantomtest.js 

enter image description here

phantomjs version 2.0 , 2.1 silently fail , hang if there syntax errors. use versions 1.9.8 or 2.5 betas. downloads here: https://bitbucket.org/ariya/phantomjs/downloads/

better still migrate puppeteer project similar api uses headless google chrome underneath.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -