Install browser binaries and matching webdrivers
Install specific browser versions for Chromium, Firefox and Edge, and their
matching selenium webdriver.
The sample below shows how to install the latest Chromium and run it using
selenium webdriver:
``javascript
import {BROWSERS} from "@eyeo/get-browser-binary";
(async function example() {
let {binary} = await BROWSERS.chromium.installBrowser("latest");
console.log(Chromium executable location: ${binary});
let driver = await BROWSERS.chromium.getDriver("latest");
await driver.navigate().to("https://example.com/");
await driver.quit();
})();
`
test/browsers.js
provides other usage examples of the library.
For more information, please refer to the API documention.
If you are already on the documentation page, you may find the API contents on
the right side.
- Chromium >= 77 (Chromium ARM >= 92)
- Firefox >= 68
- Edge >= 114 (Linux), Edge >= latest (MacOS, Windows)
Set the VERBOSE environment variable to "true" to get verbose logging on
download requests.
It is possible to run browsers offline as long as they have been previously
installed. Example:
`javascript
// Online
let {binary} = await BROWSERS[browser].installBrowser(version);
console.log(binary); // keep the browser binary location to use it offline
let driver = await BROWSERS[browser].getDriver(version); // let the driver binary download
// Offline
let customBrowserBinary = "
let driver = await BROWSERS[browser].getDriver(version, {customBrowserBinary});
`
- Node >= 18
- npm >= 9
`shell`
npm install
All browser and webdriver files will be extracted to the ./browser-snapshots.gitignore
folder, which probably makes sense to be ignored (for instance, by adding it to).
On the other hand, ./browser-snapshots/ will hold all the
downloaded installation files required by . Therefore, it may be./browser-snapshots/*/cache
useful to add to the list of cached folders in
your CI pipeline configuration.
Running all tests:
`shell`
npm test
The grep option filters the tests to run with a regular expression. Example:
`shell`
npm test -- --grep "chromium.*latest"
The timeout option overrides the timeout defined by .mocharc.json.
Increasing the timeout may be useful on slow connection environments:
`shell`
npm test -- --timeout
By default, tests delete the ./browser-snapshots before each Browser suiteTEST_KEEP_SNAPSHOTS
runs. To change that behavior you may set the environmenttrue
variable to . Example:
`shell`
TEST_KEEP_SNAPSHOTS=true npm test
Tests use a local http server, which is managed by the npm test command. If
needed, the test server can also run independently:
`shell`
npm run test-server
Then tests may be executed on a separate session. Example:
`shell`
npm run test-suite -- --grep "chromium.*latest"
Useful to reproduce the CI environment of the test:browsers:linux job.
#### Intel/AMD architecture
`shell`
docker build -f test/docker/Dockerfile -t browsers .
docker run --shm-size=512m -it browsers
The grep and timeout options can also be used on Docker via the TEST_ARGS
parameter:
`shell`
docker run --shm-size=512m -e TEST_ARGS="--grep chromium.*latest --timeout 100000" -it browsers
#### ARM architecture (M1/M2 Apple Silicon)
The run is done emulating the AMD architecture. Requirements:
- macOS >= 13 (Ventura)
- Rosetta
- The feature "Use Rosetta for x86/amd64 emulation on Apple Silicon" enabled in Docker
The --platform option should be used when running the image:
`shell`
docker run --platform linux/amd64 --shm-size=512m -e TEST_ARGS="--grep chromium.*latest" -it browsers
`shell``
npm run docs
All contributors to this project are required to read and follow our
code of conduct.