Node - phantom createPage () never calls a callback

I have been using nodejs with the node - phantom module for some time. It worked fine. Now I try this on another machine, and the same code example does not work:

var Scan=function(request,response) { var parsedURL=url.parse(request.url,true); if(parsedURL.query.site) { console.log("scanning "+parsedURL.query.site); phantom.create(function(err,ph) { console.log(err); return ph.createPage(function(err,page) { console.log(err); return page.open(parsedURL.query.site, function(err,status) { console.log("opened site? ", status); if (status=="fail") { response.writeHead(404, {'Content-Type': 'text/plain'}); response.end('URL not found'); return; } var filename="temp.jpg'; console.log(filename); page.render(filename,function(err){ if (err) { console.log(err); return; } page.close(function(){ response.writeHead(404, {'Content-Type': 'text/plain'}); response.end('URL not found'); }); }); console.log("opened site? ", status); if (status=="fail") { response.writeHead(404, {'Content-Type': 'text/plain'}); response.end('URL not found'); return; } var filename="temp.jpg'; console.log(filename); page.render(filename,function(err){ if (err) { console.log(err); return; } page.close(function(){ response.writeHead(404, {'Content-Type': 'text/plain'}); response.end('URL not found'); }); }); }); }); }); } } 

It never gets inside the createPage () callback, and it looks like there is no connection between nodejs and phantomjs. Nodejs version: 0.10.10 phantomjs version: 1.9.1

How can I check what is wrong with him?

UPD: Installed a new Debian distribution, and now it sometimes causes a warning in the console.

warn - a client that does not support the client must reconnect

It looks like socket.io problem.

+4
source share
1 answer

Well, it's hard to diagnose accurately, but I tried my code with the following fixes for inconsistent quotes, and it seems to work fine on v0.10.6. These two lines look like this:

 var filename="temp.jpg'; 

you need to fix it first.

My best guess is that you have a 32-bit and 64-bit problem ... seeing how you switch machines and it fails or works. Therefore, I simulated that by installing a 32-bit node on a 64-bit system to show the troubleshooting procedure for this kind of thing:

First check the exit code:

 [ node@hip1 blah]$ phantomjs [ node@hip1 blah]$ $? -bash: 127: command not found 

follow all the symbolic links and run the executable file directly, for example, on my system:

 [ node@hip1 blah]$ which phantomjs ~/node/bin/phantomjs [ node@hip1 blah]$ ls -l ~/node/bin/phantomjs lrwxrwxrwx. 1 node node 43 Jun 16 20:06 /node/node/bin/phantomjs -> ../lib/node_modules/phantomjs/bin/phantomjs [ node@hip1 blah]$ ls -l /node/node/lib/node_modules/phantomjs/bin/phantomjs -rwxr-xr-x. 1 node node 540 Jun 16 20:14 /node/node/lib/node_modules/phantomjs/bin/phantomjs 

accomplish this ...

 [ node@hip1 blah]$ /node/node/lib/node_modules/phantomjs/bin/phantomjs /node/libs/node-v0.10.6-linux-x86/lib/node_modules/phantomjs/lib/phantom/bin/phantomjs: error while loading shared libraries: libfreetype.so.6: cannot open shared object file: No such file or directory 

And, pay attention to the .6 at the end of this library, that it is a 64-bit system, but we installed a 32-bit node to avoid memory problems, and also noted the best performance with it. So npm install phantomjs goes and gets a 32 bit version of this. So now I need the Debian i686 versions of these libraries that will not be installed unless I specify - I will get x86_64 versions instead. So do a few of them:

yum install freetype-devel.i686 or when using debian apt-get install . You may also need libfontconfig.so.1, which is located in fontconfig-devel.i686.

And finally!

phantomjs>

After that, everything should work.

0
source

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


All Articles