-
-
Save vatan18/8f92634f178f8036995bc161ed1e75d9 to your computer and use it in GitHub Desktop.
chrome-driver issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const https = require('https'); | |
const fs = require('fs'); | |
const unzipper = require('unzipper'); | |
const CHROME_DRIVER_ENDPOINT = 'https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json'; | |
https.get(CHROME_DRIVER_ENDPOINT, (res) => { | |
let data = ''; | |
res.on('data', (chunk) => { | |
data += chunk; | |
}); | |
res.on('end', () => { | |
try { | |
const versions = JSON.parse(data); | |
const chromeVersion = versions.channels.Stable.version; // Change to the version you need | |
const chromeDriverVersion = versions.channels.Stable.downloads.chromedriver.find(driver => driver.url.includes(chromeVersion)).version; | |
const chromeDriverUrl = versions.channels.Stable.downloads.chromedriver.find(driver => driver.url.includes(chromeVersion)).url; | |
const file = fs.createWriteStream(`chromedriver_${chromeDriverVersion}.zip`); | |
https.get(chromeDriverUrl, (response) => { | |
response.pipe(file); | |
file.on('finish', () => { | |
file.close(); | |
console.log('ChromeDriver downloaded successfully.'); | |
// Unzip ChromeDriver file | |
fs.createReadStream(`chromedriver_${chromeDriverVersion}.zip`) | |
.pipe(unzipper.Extract({ path: '.' })) | |
.on('close', () => { | |
console.log('ChromeDriver unzipped successfully.'); | |
fs.unlink(`chromedriver_${chromeDriverVersion}.zip`, (err) => { | |
if (err) { | |
console.error('Error deleting zip file:', err); | |
} else { | |
console.log('Zip file deleted.'); | |
} | |
}); | |
}) | |
.on('error', (err) => { | |
console.error('Error unzipping ChromeDriver:', err); | |
}); | |
}); | |
}).on('error', (err) => { | |
fs.unlink(`chromedriver_${chromeDriverVersion}.zip`, (unlinkErr) => { | |
if (unlinkErr) { | |
console.error('Error deleting zip file:', unlinkErr); | |
} | |
console.error(`Error downloading ChromeDriver: ${err.message}`); | |
}); | |
}); | |
} catch (error) { | |
console.error('Error parsing JSON:', error); | |
} | |
}); | |
}).on('error', (err) => { | |
console.error(`Error fetching ChromeDriver version: ${err.message}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment