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