Could you use npm modules by using require() in phantomJS? It seems to be able to load javascript files so maybe this is possible?
PhantomJS is a discontinued headless browser used for automating web page interaction.
For Windows Download the zip file, unpack it and you will get an executable phantom.exe. Set the PATH environment variable to the path of phantom.exe file. Open a new command prompt and type phantomjs –v. It should give you the current version of PhantomJS that is running.
That is entirely depends on the nodejs module. It won't work if nodejs module requires some support via native function interface.(npm modules like http, socket.io, will not work on phantomjs, because it dependents on native interfaces)
Pure JavaScript nodejs modules should work on phantomjs too.
fyi, phantomjs has an aproximation of commonjs.
you can not use amd modules in phantomjs, and I do not know of any amd loader (like requirejs) that works in phantomjs
Update (2015): I have been using commonjs modules in PhantomJs 1.x and 2.x, they work well with one caveat: you can not use source-mapping (at the bottom of the file, looks like //# sourceMappingURL=index.js.map
) as it will cause the PhantomJs module loader to fail. Otherwise, commonjs modules will load normally.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With