Why do Phantom, Casper, and Meteor need their own

2019-02-22 23:04发布

问题:

Phantom and Meteor are built off Node, and Casper is built off Phantom. Why do they each need their own separate executable, rather than being libraries you require through Node.js?

(I find it makes them harder to work with, especially on Windows.)

回答1:

phantomjs is completely separate from node:

http://phantomjs.org/faq.html

Q: Why is PhantomJS not written as Node.js module?

A: The short answer: "No one can serve two masters."

A longer explanation is as follows.

As of now, it is technically very challenging to do so.

Every Node.js module is essentially "a slave" to the core of Node.js, i.e. "the master". In its current state, PhantomJS (and its included WebKit) needs to have the full control (in a synchronous matter) over everything: event loop, network stack, and JavaScript execution.

If the intention is just about using PhantomJS right from a script running within Node.js, such a "loose binding" can be achieved by launching a PhantomJS process and interact with it.

CasperJS is built on top of node, so it obviously isn't a node module by itself. Although in that case, you can use SpookyJS with node.

Meteor really should be more tightly coupled with node. There's a similar framework Derby built for use as a module.