Chromium binaries (chromium version corresponds to package version) for Node.js projects
npm install chromium-binaryThis is fork of node-chromium by Dmytro Tolstyi.
node-chromium allows you to easily add Chromium binaries of desired version to your project and use it for automation, testing, web scraping or just for fun.
Chromium version will correspond to package version, i.e. if package version is 60.0.3112-0 then chromium 60.0.3112.0 will be installed.
--save-dev) or production dependencies (--save).```
npm install --save chromium-binary
During the installation process node-chromium will download corresponded chromium version and extract into libraries folder. As soon as installation is finished, you are ready to use Chromium in your project:
`js
const chromiumBinary = require('chromium-binary');
const {execFile} = require('child_process');
execFile(chromiumBinary.path, ['https://google.com'], err => {
console.log('Hello Google!');
});
`
``
npm install --save chromium-binary@60.0.3112-0 chromedriver@2.33.0 selenium-webdriver@3.6.0
After the installation is finished, create simple script that opens Google Search home page and takes it's screenshot in headless mode.
`js
const fs = require('fs');
const webdriver = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
const chromiumBinary = require('chromium-binary');
require('chromedriver');
async function start() {
let options = new chrome.Options();
options.setChromeBinaryPath(chromiumBinary.path);
options.addArguments('--headless');
options.addArguments('--disable-gpu');
options.addArguments('--window-size=1280,960');
const driver = await new webdriver.Builder()
.forBrowser('chrome')
.setChromeOptions(options)
.build();
await driver.get('http://google.com');
console.log('Hello Google!');
await takeScreenshot(driver, 'google-start-page');
await driver.quit();
}
async function takeScreenshot(driver, name) {
await driver.takeScreenshot().then((data) => {
fs.writeFileSync(name + '.png', data, 'base64');
console.log('Screenshot is saved');
});
}
start();
``