Skip to content

Instantly share code, notes, and snippets.

@vipyne
Last active April 28, 2023 05:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vipyne/c0c53abf0476a5b10ac7b90f581a35f6 to your computer and use it in GitHub Desktop.
Save vipyne/c0c53abf0476a5b10ac7b90f581a35f6 to your computer and use it in GitHub Desktop.
selenium-webdriver with chromedriver
{
"name": "selenium-webdriver-mvp",
"version": "1.0.0",
"description": "webrtc friendly selenium-webdriver with chromedriver",
"main": "selenium-webdriver-mvp.js",
"dependencies": {
"selenium-webdriver": "^4.0.0-alpha.7"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "vipyne",
"license": "BSD-2-Clause"
}
const execSync = require('child_process').execSync;
const webdriver = require(`selenium-webdriver`);
const { Options: chromeOptions } = require(`selenium-webdriver/chrome`);
async function aChromedriver() {
const chrOptions = new chromeOptions();
chrOptions.addArguments('headless');
chrOptions.addArguments('no-sandbox');
// webrtc
chrOptions.addArguments('use-fake-ui-for-media-stream');
chrOptions.addArguments('use-fake-device-for-media-stream');
// custom fake streams
chrOptions.addArguments('allow-file-access-from-files');
chrOptions.addArguments('use-file-for-fake-video-capture=daily.y4m');
chrOptions.addArguments('use-file-for-fake-audio-capture=audio.wav');
// optional; can be useful in local dev
chrOptions.addArguments('ignore-certificate-errors');
chrOptions.addArguments('enable-logging');
chrOptions.addArguments('verbose');
const driver = await new webdriver.Builder()
.forBrowser('chrome')
.setChromeOptions(chrOptions)
.build();
try {
await driver.get('https://your-domain.staging.daily.co/room')
} catch(e) {
console.log("_____error getting url:", e)
}
return driver;
}
async function startChromedrivers(numOfInstances) {
let instances = new Array(numOfInstances).fill(true);
try {
await Promise.all(instances.map(() => aChromedriver()));
} catch(e) {
console.log("_____error spinning up webdrivers:", e)
}
}
try {
execSync(`which chromedriver`);
} catch (e) {
console.log(`_____download chromedriver from "https://chromedriver.chromium.org/downloads" \n` +
`_____and ensure it is in $PATH ('/usr/local/bin/' is a solid bet) \n`, e);
process.exit(1);
}
startChromedrivers(4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment