UNPKG

11.8 kBMarkdownView Raw
1# ChromeDriver
2
3[![Build app](https://github.com/giggio/node-chromedriver/actions/workflows/build.yml/badge.svg)](https://github.com/giggio/node-chromedriver/actions/workflows/build.yml)
4[![npm](https://img.shields.io/npm/dt/chromedriver.svg)](https://www.npmjs.com/package/chromedriver)
5
6An NPM wrapper for Selenium [ChromeDriver](https://sites.google.com/chromium.org/driver/).
7
8## Building and Installing
9
10```shell
11npm install chromedriver
12```
13
14Or grab the source and
15
16```shell
17node ./install.js
18```
19
20What this is really doing is just grabbing a particular "blessed" (by
21this module) version of ChromeDriver. As new versions are released
22and vetted, this module will be updated accordingly.
23
24The package has been set up to fetch and run ChromeDriver for MacOS (darwin),
25Linux based platforms (as identified by Node.js), and Windows. If you
26spot any platform weirdness, let us know or send a patch.
27
28## Force download
29
30By default this package, when installed, will search for an existing
31Chromedriver binary in your configured temp directory. If found, and it is the
32correct version, it will simply copy it to your node_modules directory. You can
33force it always download by configuring it:
34
35```shell
36npm install chromedriver --chromedriver-force-download
37```
38
39Or add property to your [`.npmrc`](https://docs.npmjs.com/files/npmrc) file.
40
41```ini
42chromedriver_force_download=true
43```
44
45Another option is to use PATH variable `CHROMEDRIVER_FORCE_DOWNLOAD`.
46
47```shell
48CHROMEDRIVER_FORCE_DOWNLOAD=true npm install chromedriver
49```
50
51## Custom binaries url
52
53This allows you to use your own endpoints for metadata and binaries. It is useful in air gapped
54scenarios or if you have download restrictions, such as firewalls.
55
56This was changed for version 115 and greater
57([see details](https://groups.google.com/g/chromedriver-users/c/clpipqvOGjE)),
58but implemented in this package starting with version
59`114.0.2`. To see the configuration to prior versions check out this
60[README.md](https://github.com/giggio/node-chromedriver/tree/114.0.1#custom-binaries-url)
61at the latest tag where it was using the legacy urls (`114.0.1`).
62
63### For versions >= 115
64
65There are two urls that need to be configured, one for metadata and one for binaries.
66The one for metadata is the "CDN url", and the one for binaries is the "CDN binaries url".
67See [Chrome for Testing](https://googlechromelabs.github.io/chrome-for-testing/) to understand
68how these urls work.
69
70Npm config:
71
72For metadata use `chromedriver_cdnurl`. The default is `https://googlechromelabs.github.io`. You need to either supply the binary download endpoint, or the binaries url config, see bellow.
73
74For binaries use `chromedriver_cdnbinariesurl`. The default is to search for the download url using
75`$chromedriver_cdnurl/chrome-for-testing/[version].json`, which forms a URL like:
76https://googlechromelabs.github.io/chrome-for-testing/122.0.6261.57.json.
77
78The resulting url will be something like:
79https://storage.googleapis.com/chrome-for-testing-public/122.0.6261.57/linux64/chromedriver-linux64.zip.
80
81Keep in mind that this last url is just an example and it might change (as it has happened in the past).
82
83```shell
84npm install chromedriver --chromedriver_cdnurl=https://npmmirror.com/metadata --chromedriver_cdnbinariesurl=https://npmmirror.com/binaries
85```
86
87Or add these properties to your [`.npmrc`](https://docs.npmjs.com/cli/configuring-npm/npmrc) file:
88
89```ini
90chromedriver_cdnurl=https://npmmirror.com/metadata
91chromedriver_cdnbinariesurl=https://npmmirror.com/binaries
92```
93
94Another option is to use the environment variables `CHROMEDRIVER_CDNURL` and `CHROMEDRIVER_CDNBINARIESURL`.
95
96```shell
97CHROMEDRIVER_CDNURL=https://npmmirror.com/metadata CHROMEDRIVER_CDNBINARIESURL=https://npmmirror.com/binaries npm install chromedriver
98```
99
100### For versions < 115
101
102There is one url to both metadata and binaries.
103
104To use a mirror of the ChromeDriver binaries use npm config property `chromedriver_legacy_cdnurl`.
105Default is `https://chromedriver.storage.googleapis.com`.
106
107```shell
108npm install chromedriver --chromedriver_legacy_cdnurl=https://npmmirror.com/mirrors/chromedriver --chromedriver_version=LATEST_114
109```
110
111Or add a property to your [`.npmrc`](https://docs.npmjs.com/files/npmrc) file:
112
113```ini
114chromedriver_legacy_cdnurl=https://npmmirror.com/mirrors/chromedriver
115```
116
117Another option is to use the environment variable `CHROMEDRIVER_LEGACY_CDNURL`.
118
119```shell
120CHROMEDRIVER_LEGACY_CDNURL=https://npmmirror.com/mirrors/chromedriver npm install chromedriver --chromedriver_version=LATEST_114
121```
122
123## Custom binaries file
124
125To get the chromedriver from the filesystem instead of a web request use the npm config property `chromedriver_filepath`.
126
127```shell
128npm install chromedriver --chromedriver_filepath=/path/to/chromedriver_mac64.zip
129```
130
131Or add property to your [`.npmrc`](https://docs.npmjs.com/files/npmrc) file.
132
133```ini
134chromedriver_filepath=/path/to/chromedriver_mac64.zip
135```
136
137Another option is to use the PATH variable `CHROMEDRIVER_FILEPATH`
138
139```shell
140CHROMEDRIVER_FILEPATH=/path/to/chromedriver_mac64.zip
141```
142
143This variable can be used to set either a `.zip` file or the binary itself, eg:
144
145```shell
146CHROMEDRIVER_FILEPATH=/bin/chromedriver
147```
148
149## Custom download options
150
151Install through a proxy.
152
153```shell
154npm config set proxy http://[user:pwd]@domain.tld:port
155npm config set https-proxy http://[user:pwd]@domain.tld:port
156```
157
158Use different User-Agent.
159
160```shell
161npm config set user-agent "Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0"
162```
163
164## Skipping chromedriver download
165
166You may wish to skip the downloading of the chromedriver binary file, for example if you know for certain that it is already there or if you want to use a system binary and just use this module as an interface to interact with it.
167
168To achieve this you can use the npm config property `chromedriver_skip_download`.
169
170```shell
171npm install chromedriver --chromedriver_skip_download=true
172```
173
174Or add property to your [`.npmrc`](https://docs.npmjs.com/files/npmrc) file.
175
176```ini
177chromedriver_skip_download=true
178```
179
180Another option is to use the PATH variable `CHROMEDRIVER_SKIP_DOWNLOAD`
181
182```shell
183CHROMEDRIVER_SKIP_DOWNLOAD=true
184```
185
186## Running
187
188```shell
189bin/chromedriver [arguments]
190```
191
192And npm will install a link to the binary in `node_modules/.bin` as
193it is wont to do.
194
195## Running with Selenium WebDriver
196
197```javascript
198require('chromedriver');
199var webdriver = require('selenium-webdriver');
200var driver = new webdriver.Builder()
201 .forBrowser('chrome')
202 .build();
203```
204
205(Tested for selenium-webdriver version `2.48.2`)
206
207The path will be added to the process automatically, you don't need to configure it.
208But you can get it from `require('chromedriver').path` if you want it.
209
210## Running via node
211
212The package exports a `path` string that contains the path to the
213chromedriver binary/executable.
214
215Below is an example of using this package via node.
216
217```javascript
218var childProcess = require('child_process');
219var chromedriver = require('chromedriver');
220var binPath = chromedriver.path;
221
222var childArgs = [
223 'some argument'
224];
225
226childProcess.execFile(binPath, childArgs, function(err, stdout, stderr) {
227 // handle results
228});
229
230```
231
232You can also use the start and stop methods:
233
234```javascript
235var chromedriver = require('chromedriver');
236
237args = [
238 // optional arguments
239];
240chromedriver.start(args);
241// run your tests
242chromedriver.stop();
243
244```
245
246With the latest version, you can optionally receive a Promise from the `chromedriver.start` function:
247
248```javascript
249var returnPromise = true;
250chromedriver
251 .start(args, returnPromise)
252 .then(() => {
253 console.log('chromedriver is ready');
254 });
255```
256
257Note: if your tests are ran asynchronously, chromedriver.stop() will have to be
258executed as a callback at the end of your tests
259
260## Versioning
261
262The NPM package version tracks the version of chromedriver that will be installed,
263with an additional build number that is used for revisions to the installer.
264You can use the package version number to install a specific version, or use the
265setting to a specific version. If there is a new Chromedriver version available which is not yet available as a version of `node-chromedriver`, the npm command `npm run update-chromedriver` in this repository can be used to make the required updates to this module, please submit the change as a PR. To always install the latest version of Chromedriver,
266use `LATEST` as the version number:
267
268```shell
269npm install chromedriver --chromedriver_version=LATEST
270```
271
272Or add property to your [`.npmrc`](https://docs.npmjs.com/files/npmrc) file.
273
274```ini
275chromedriver_version=LATEST
276```
277
278Another option is to use env variable `CHROMEDRIVER_VERSION`.
279
280```shell
281CHROMEDRIVER_VERSION=LATEST npm install chromedriver
282```
283
284You can force the latest release for a specific major version by specifying `LATEST_{VERSION_NUMBER}`:
285
286```shell
287CHROMEDRIVER_VERSION=LATEST_80 npm install chromedriver
288```
289
290You can also force a different version of chromedriver by replacing `LATEST` with a version number:
291
292```shell
293CHROMEDRIVER_VERSION=75.0.3770.140 npm install chromedriver
294```
295
296## Detect ChromeDriver Version
297
298The NPM package version may not be always compatible to your Chrome version.
299To get the chromedriver that corresponds to the version of Chrome installed,
300you can use the npm config property `detect_chromedriver_version`.
301
302```shell
303npm install chromedriver --detect_chromedriver_version
304```
305
306Or add property to your [`.npmrc`](https://docs.npmjs.com/files/npmrc) file.
307
308```ini
309detect_chromedriver_version=true
310```
311
312Another option is to use environment variable `DETECT_CHROMEDRIVER_VERSION`.
313
314```shell
315DETECT_CHROMEDRIVER_VERSION=true npm install chromedriver
316```
317
318**Note:** When the property `detect_chromedriver_version` is provided,
319`chromedriver_version` and `chromedriver_filepath` properties are ignored.
320
321## Include Chromium
322
323If you don't have Chrome installed, you can check for Chromium version instead by setting the argument `include_chromium` to `true`.
324
325```shell
326npm install chromedriver --include_chromium
327```
328
329Or add property to your [`.npmrc`](https://docs.npmjs.com/files/npmrc) file.
330
331```ini
332include_chromium=true
333```
334
335Another option is to use environment variable `INCLUDE_CHROMIUM`.
336
337```shell
338INCLUDE_CHROMIUM=true npm install chromedriver
339```
340
341**Note:** The property `INCLUDE_CHROMIUM` is ignored if the property `DETECT_CHROMEDRIVER_VERSION` is not used.
342
343## A Note on chromedriver
344
345Chromedriver is not a library for NodeJS.
346
347This is an _NPM wrapper_ and can be used to conveniently make ChromeDriver available.
348It is not a Node.js wrapper.
349
350## Supported Node.js versions
351
352We will do our best to support every supported Node.js versions.
353See [nodejs/Release](https://github.com/nodejs/Release) for
354the current supported versions. You can also view our
355[build scripts](https://github.com/giggio/node-chromedriver/blob/main/.github/workflows/build.yml#L41) and check the versions there.
356
357## Contributing
358
359Questions, comments, bug reports, and pull requests are all welcome. Submit them at
360[the project on GitHub](https://github.com/giggio/node-chromedriver/).
361
362Bug reports that include steps-to-reproduce (including code) are the
363best. Even better, make them in the form of pull requests.
364
365We have added
366[VS Code Remote support with containers](https://code.visualstudio.com/docs/remote/containers).
367If you are on Windows, set `git config core.autocrlf input` so you don't get git errors.
368
369## Author
370
371[Giovanni Bassi](https://github.com/giggio), with collaboration from
372[lots of good people](https://github.com/giggio/node-chromedriver/graphs/contributors).
373
374Thanks for Obvious and their PhantomJS project for heavy inspiration! Check their project on [Github](https://github.com/Obvious/phantomjs/).
375
376## License
377
378Licensed under the Apache License, Version 2.0.