Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Haxe externs for phantomjs
Haxe Shell
Tree: 14bb40610b

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.


phantomjs-hx is a haxe extern for phantomjs.

It contains typedefs and externs for all of the common modules and entities. It also contains the PhantomTools class, which enable some Haxe-specific functionality.

For now, PhantomTools lets you more easily work with Webpage.evaluate. See more information on the [phantomjs api](\)).

Webpage.evaluate() accepts a callback that executes locally in a new virtual browser instance. This page instance is separate from the phantomjs instance, so none of the scoped variables are avaialble. Naturally, this virtual instance will not have the Haxe standard lib by default, such as trace, Hash, etc. The current method of dealing with this is to include a small js file in the evaluated page containing the compiled haxe libs.

PhantomTools provides "injectThis" which will inject the current script into the page, which will provide all of the methods from your phantomjs script in the page you are evaluating.

var page = WebPage.create();

The scope, however, will still not be available.

It is also necessary to prevent the phantomjs script from executing its static main function in the evaluated page. You can check the result from PhantomTools.inPhantom() to avoid running main() in an evaluated page:

static function main(){
  if (!PhantomTools.inPhantom()) return;


Keep in mind that PhantomTools.injectThis() loads phantomjs application code into a sandboxed page instance, which may be running a page with unknown third party code. Be cautious when using it, since it could potentially leak passwords, credentials, etc. that are contained in the phantomjs script source.


The require("webpage").create() syntax is not used to create phantomjs objects (e.g. WebPages). Instead, you can simply use the "create" method for the class. (e.g. WebPage.create()), which conforms to Haxe syntax, and aliases the correct js code.

Something went wrong with that request. Please try again.