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