UNPKG

8.76 kBMarkdownView Raw
1phantomjs
2==================
3
4An 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).
9We changed the name to [phantomjs-prebuilt](https://www.npmjs.com/package/phantomjs-prebuilt) at
10the 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
16Building and Installing
17-----------------------
18
19```shell
20npm install phantomjs
21```
22
23Or grab the source and
24
25```shell
26node ./install.js
27```
28
29What this installer is really doing is just grabbing a particular "blessed" (by
30this module) version of Phantom. As new versions of Phantom are released
31and vetted, this module will be updated accordingly.
32
33Running
34-------
35
36```shell
37bin/phantomjs [phantom arguments]
38```
39
40And npm will install a link to the binary in `node_modules/.bin` as
41it is wont to do.
42
43Running via node
44----------------
45
46The package exports a `path` string that contains the path to the
47phantomjs binary/executable.
48
49Below is an example of using this package via node.
50
51```javascript
52var path = require('path')
53var childProcess = require('child_process')
54var phantomjs = require('phantomjs')
55var binPath = phantomjs.path
56
57var childArgs = [
58 path.join(__dirname, 'phantomjs-script.js'),
59 'some other argument (passed to phantomjs script)'
60]
61
62childProcess.execFile(binPath, childArgs, function(err, stdout, stderr) {
63 // handle results
64})
65
66```
67
68Versioning
69----------
70
71The major and minor number tracks the version of PhantomJS that will be
72installed. The patch number is incremented when there is either an installer
73update or a patch build of the phantom binary.
74
75Pre-2.0, this package was published to NPM as [phantomjs](https://www.npmjs.com/package/phantomjs).
76We changed the name to [phantomjs-prebuilt](https://www.npmjs.com/package/phantomjs-prebuilt) at
77the request of PhantomJS team.
78
79Deciding Where To Get PhantomJS
80-------------------------------
81
82By default, this package will download phantomjs from our [releases](https://github.com/Medium/phantomjs/releases/).
83This should work fine for most people.
84
85##### Downloading from a custom URL
86
87If github is down, or the Great Firewall is blocking github, you may need to use
88a different download mirror. To set a mirror, set npm config property `phantomjs_cdnurl`.
89
90Alternatives include `https://bitbucket.org/ariya/phantomjs/downloads` (the official download site)
91and `http://cnpmjs.org/downloads`.
92
93```Shell
94npm install phantomjs --phantomjs_cdnurl=https://bitbucket.org/ariya/phantomjs/downloads
95```
96
97Or add property into your `.npmrc` file (https://www.npmjs.org/doc/files/npmrc.html)
98
99```
100phantomjs_cdnurl=https://bitbucket.org/ariya/phantomjs/downloads
101```
102
103Another option is to use PATH variable `PHANTOMJS_CDNURL`.
104```shell
105PHANTOMJS_CDNURL=https://bitbucket.org/ariya/phantomjs/downloads npm install phantomjs
106```
107
108##### Using PhantomJS from disk
109
110If you plan to install phantomjs many times on a single machine, you can
111install the `phantomjs` binary on PATH. The installer will automatically detect
112and use that for non-global installs.
113
114Cross-Platform Repositories
115---------------------------
116
117PhantomJS needs to be compiled separately for each platform. This installer
118finds a prebuilt binary for your operating system, and downloads it.
119
120If you check your dependencies into git, and work on a cross-platform
121team, then you need to tell NPM to rebuild any platform-specific dependencies. Run
122
123```shell
124npm rebuild
125```
126
127as part of your build process. This problem is not specific to PhantomJS, and this
128solution will work for any NodeJS package with native or platform-specific code.
129
130If you know in advance that you want to install PhantomJS for a specific architecture,
131you can set the environment variables: `PHANTOMJS_PLATFORM`
132(to set target platform) and `PHANTOMJS_ARCH` (to set target
133arch), where `platform` and `arch` are valid values for
134[process.platform and process.arch](https://nodejs.org/api/process.html).
135
136A Note on PhantomJS
137-------------------
138
139PhantomJS is not a library for NodeJS. It's a separate environment and code
140written for node is unlikely to be compatible. In particular PhantomJS does
141not expose a Common JS package loader.
142
143This is an _NPM wrapper_ and can be used to conveniently make Phantom available
144It is not a Node JS wrapper.
145
146I have had reasonable experiences writing standalone Phantom scripts which I
147then drive from within a node program by spawning phantom in a child process.
148
149Read the PhantomJS FAQ for more details: http://phantomjs.org/faq.html
150
151### Linux Note
152
153An 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
159Troubleshooting
160---------------
161
162##### Installation fails with `spawn ENOENT`
163
164This 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
169Check your specific error message for more information.
170
171##### Installation fails with `Error: EPERM` or `operation not permitted` or `permission denied`
172
173This error means that NPM was not able to install phantomjs to the file system. There are three
174major 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
182This error means that something went wrong with your internet connection, and the installer
183was 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
187Do you live in China, or a country with an authoritarian government? We've seen problems where
188the GFW or local ISP blocks github, preventing the installer from downloading the binary.
189
190Try visiting [the download page](https://bitbucket.org/ariya/phantomjs/downloads) manually.
191If that page is blocked, you can try using a different CDN with the `PHANTOMJS_CDNURL`
192env variable described above.
193
194##### I am behind a corporate proxy that uses self-signed SSL certificates to intercept encrypted traffic.
195
196You 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```
200npm set strict-ssl false
201```
202
203WARNING: Turning off `strict-ssl` leaves you vulnerable to attackers reading
204your encrypted traffic, so run this at your own risk!
205
206##### I tried everything, but my network is b0rked. What do I do?
207
208If you install PhantomJS manually, and put it on PATH, the installer will try to
209use the manually-installed binaries.
210
211##### I'm on Debian or Ubuntu, and the installer failed because it couldn't find `node`
212
213Some Linux distros tried to rename `node` to `nodejs` due to a package
214conflict. 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)
216recommends that you run `apt-get install nodejs-legacy` to symlink `node` to `nodejs`
217on those platforms, or many NodeJS programs won't work properly.
218
219Contributing
220------------
221
222Questions, 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
226out an OCLA (it should be pretty painless).
227
228Bug reports that include steps-to-reproduce (including code) are the
229best. Even better, make them in the form of pull requests.
230
231Author
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
239License
240-------
241
242Copyright 2012 [A Medium Corporation](http://medium.com/).
243
244Licensed under the Apache License, Version 2.0.
245See the top-level file `LICENSE.txt` and
246(http://www.apache.org/licenses/LICENSE-2.0).