can phantomjs work with node.js?

phantomjs-node isn’t an official supported npm package for phantomjs. Instead, it implements a “nauseously clever bridge” between node and phantom by creating a web server that uses websockets to serve as an IPC channel between node and phantom. I’m not making this up:

So we communicate with PhantomJS by spinning up an instance of ExpressJS, opening Phantom in a subprocess, and pointing it at a special webpage that turns socket.io messages into alert() calls. Those alert() calls are picked up by Phantom and there you go!

So I wouldn’t be surprised if phantomjs-node works, doesn’t work, fails silently, or fails spectacularly. Nor would I expect anyone other than the author of phantomjs-node to be able to troubleshoot phantomjs-node.

The answer to your original question is the answer from the phantomjs faq: No. Phantom and node have irreconcilable differences. Both expect to have complete control over fundamental low-level functionality like the event loop, the network stack, and JS execution so they can’t cooperate within the same process.

Leave a Comment