Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Provide custom WebDriver function for evaluating PhantomJS scripts directly #195

watsonmw opened this Issue · 8 comments

3 participants


PhantomJS has a bunch of useful functionality that probably will never be exposed via the base Selenium WebDriver wire protocol. Access to the PhantomJS scripting language from GhostDriver would be useful for a number of reasons:

  • WebDriver doesn't support a way of injecting JavaScript into a page before the page is loaded. PhantomJS allows you to override all sorts of DOM functions, to return customized values or check what functionality the page uses (see detectsniff.js).

  • WebDriver has a nice automation interface and but is lacking in the browser configuration and setup department. For example, PhantomJS allows the viewport and 'clipping rect' to be setup, allowing screenshots that may be closer to what a user would see in a real browser. WebDriver always gives the full page size.

  • It would make it easier to migrate between PhantomJS and WebDriver scripts. As in there would be an out, if some part of WebDriver functionality didn't match the PhantomJS functionality.

The downside of allowing PhantomJS to be called from WebDriver is that user scripts may interfere with the GhostDriver code. Like resetting callbacks for example. I think this can be mitigated with some documented warnings though.

I have an example implementation working with GhostDriver & the Java WebDriver bindings. It seems to work well, I'll clean it up and add it here.


I filed here with a patch:

So that issue can probably be closed, if this is a better place for it.


Btw, setting Custom-Headers is now part of GhostDriver 1.0.4.

But I still want to add support for this feature: it's general and can be extremely useful.
A pull request?


+1 for this patch. It looks pretty clean and straightforward (only 200 lines).

Another great use case: AJAX frameworks. This patch would allow me to track AJAX requests and continue my test when I see that the server replied to a request. It would even allow me to test content of AJAX requests.


Mark (@watsonmw), if you think your patch is still perfectly valid, I'll allocate sometime to port it into.

But if you want to make changes (since I made half a century pass by and things might have evolved...), and provide a pull request off the latest code, be my guest.

I'll wait a day or two for reply.


Implemented by #262

@detro detro closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.