4 An NPM installer for [PhantomJS](http://phantomjs.org/), headless webkit with JS API.
6 [![Build Status](https://travis-ci.org/Medium/phantomjs.svg?branch=master)](https://travis-ci.org/Medium/phantomjs)
8 Building and Installing
9 -----------------------
15 Or grab the source and
21 What this installer is really doing is just grabbing a particular "blessed" (by
22 this module) version of Phantom. As new versions of Phantom are released
23 and vetted, this module will be updated accordingly.
29 bin/phantomjs [phantom arguments]
32 And npm will install a link to the binary in `node_modules/.bin` as
38 The package exports a `path` string that contains the path to the
39 phantomjs binary/executable.
41 Below is an example of using this package via node.
44 var path = require('path')
45 var childProcess = require('child_process')
46 var phantomjs = require('phantomjs')
47 var binPath = phantomjs.path
50 path.join(__dirname, 'phantomjs-script.js'),
51 'some other argument (passed to phantomjs script)'
54 childProcess.execFile(binPath, childArgs, function(err, stdout, stderr) {
63 The major and minor number tracks the version of PhantomJS that will be
64 installed. The patch number is incremented when there is either an installer
65 update or a patch build of the phantom binary.
67 Pre-2.0, this package was published to NPM as [phantomjs](https://www.npmjs.com/package/phantomjs).
68 We changed the name to [phantomjs](https://www.npmjs.com/package/phantomjs) at
69 the request of PhantomJS team.
71 Deciding Where To Get PhantomJS
72 -------------------------------
74 By default, this package will download phantomjs from our [releases](https://github.com/Medium/phantomjs/releases/).
75 This should work fine for most people.
77 ##### Downloading from a custom URL
79 If github is down, or the Great Firewall is blocking github, you may need to use
80 a different download mirror. To set a mirror, set npm config property `phantomjs_cdnurl`.
82 Alternatives include `https://bitbucket.org/ariya/phantomjs/downloads` (the official download site)
83 and `http://cnpmjs.org/downloads`.
86 npm install phantomjs --phantomjs_cdnurl=https://bitbucket.org/ariya/phantomjs/downloads
89 Or add property into your `.npmrc` file (https://www.npmjs.org/doc/files/npmrc.html)
92 phantomjs_cdnurl=https://bitbucket.org/ariya/phantomjs/downloads
95 Another option is to use PATH variable `PHANTOMJS_CDNURL`.
97 PHANTOMJS_CDNURL=https://bitbucket.org/ariya/phantomjs/downloads npm install phantomjs
100 ##### Using PhantomJS from disk
102 If you plan to install phantomjs many times on a single machine, you can
103 install the `phantomjs` binary on PATH. The installer will automatically detect
104 and use that for non-global installs.
106 Cross-Platform Repositories
107 ---------------------------
109 PhantomJS needs to be compiled separately for each platform. This installer
110 finds a prebuilt binary for your operating system, and downloads it.
112 If you check your dependencies into git, and work on a cross-platform
113 team, then you need to tell NPM to rebuild any platform-specific dependencies. Run
119 as part of your build process. This problem is not specific to PhantomJS, and this
120 solution will work for any NodeJS package with native or platform-specific code.
122 If you know in advance that you want to install PhantomJS for a specific architecture,
123 you can set the environment variables: `PHANTOMJS_PLATFORM`
124 (to set target platform) and `PHANTOMJS_ARCH` (to set target
125 arch), where `platform` and `arch` are valid values for
126 [process.platform and process.arch](https://nodejs.org/api/process.html).
131 PhantomJS is not a library for NodeJS. It's a separate environment and code
132 written for node is unlikely to be compatible. In particular PhantomJS does
133 not expose a Common JS package loader.
135 This is an _NPM wrapper_ and can be used to conveniently make Phantom available
136 It is not a Node JS wrapper.
138 I have had reasonable experiences writing standalone Phantom scripts which I
139 then drive from within a node program by spawning phantom in a child process.
141 Read the PhantomJS FAQ for more details: http://phantomjs.org/faq.html
145 An extra note on Linux usage, from the PhantomJS download page:
147 > There is no requirement to install Qt, WebKit, or any other libraries. It
148 > however still relies on Fontconfig (the package fontconfig or libfontconfig,
149 > depending on the distribution).
154 ##### Installation fails with `spawn ENOENT`
156 This is NPM's way of telling you that it was not able to start a process. It usually means:
158 - `node` is not on your PATH, or otherwise not correctly installed.
159 - `tar` is not on your PATH. This package expects `tar` on your PATH on Linux-based platforms.
161 Check your specific error message for more information.
163 ##### Installation fails with `Error: EPERM` or `operation not permitted` or `permission denied`
165 This error means that NPM was not able to install phantomjs to the file system. There are three
166 major reasons why this could happen:
168 - You don't have write access to the installation directory.
169 - The permissions in the NPM cache got messed up, and you need to run `npm cache clean` to fix them.
170 - You have over-zealous anti-virus software installed, and it's blocking file system writes.
172 ##### Installation fails with `Error: read ECONNRESET` or `Error: connect ETIMEDOUT`
174 This error means that something went wrong with your internet connection, and the installer
175 was not able to download the PhantomJS binary for your platform. Please try again.
177 ##### I tried again, but I get `ECONNRESET` or `ETIMEDOUT` consistently.
179 Do you live in China, or a country with an authoritarian government? We've seen problems where
180 the GFW or local ISP blocks github, preventing the installer from downloading the binary.
182 Try visiting [the download page](https://bitbucket.org/ariya/phantomjs/downloads) manually.
183 If that page is blocked, you can try using a different CDN with the `PHANTOMJS_CDNURL`
184 env variable described above.
186 ##### I am behind a corporate proxy that uses self-signed SSL certificates to intercept encrypted traffic.
188 You can tell NPM and the PhantomJS installer to skip validation of ssl keys with NPM's
189 [strict-ssl](https://www.npmjs.org/doc/misc/npm-config.html#strict-ssl) setting:
192 npm set strict-ssl false
195 WARNING: Turning off `strict-ssl` leaves you vulnerable to attackers reading
196 your encrypted traffic, so run this at your own risk!
198 ##### I tried everything, but my network is b0rked. What do I do?
200 If you install PhantomJS manually, and put it on PATH, the installer will try to
201 use the manually-installed binaries.
203 ##### I'm on Debian or Ubuntu, and the installer failed because it couldn't find `node`
205 Some Linux distros tried to rename `node` to `nodejs` due to a package
206 conflict. This is a non-portable change, and we do not try to support this. The
207 [official documentation](https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager#ubuntu-mint-elementary-os)
208 recommends that you run `apt-get install nodejs-legacy` to symlink `node` to `nodejs`
209 on those platforms, or many NodeJS programs won't work properly.
214 Questions, comments, bug reports, and pull requests are all welcome. Submit them at
215 [the project on GitHub](https://github.com/Medium/phantomjs/). If you haven't contributed to an
216 [Medium](http://github.com/Medium/) project before please head over to the
217 [Open Source Project](https://github.com/Medium/open-source#note-to-external-contributors) and fill
218 out an OCLA (it should be pretty painless).
220 Bug reports that include steps-to-reproduce (including code) are the
221 best. Even better, make them in the form of pull requests.
226 [Dan Pupius](https://github.com/dpup)
227 ([personal website](http://pupius.co.uk)) and
228 [Nick Santos](https://github.com/nicks), supported by
229 [A Medium Corporation](http://medium.com/).
234 Copyright 2012 [A Medium Corporation](http://medium.com/).
236 Licensed under the Apache License, Version 2.0.
237 See the top-level file `LICENSE.txt` and
238 (http://www.apache.org/licenses/LICENSE-2.0).