| 
									
										
										
										
											2022-02-14 13:23:08 -07:00
										 |  |  | const playwright = require('playwright-core'); | 
					
						
							| 
									
										
										
										
											2021-11-18 15:32:09 -08:00
										 |  |  | const { execSync } = require('child_process'); | 
					
						
							|  |  |  | const path = require('path'); | 
					
						
							| 
									
										
										
										
											2023-07-27 05:53:45 -07:00
										 |  |  | const fs = require('fs'); | 
					
						
							| 
									
										
										
										
											2021-11-18 15:32:09 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | (async () => { | 
					
						
							|  |  |  |   const dir = process.argv[2]; | 
					
						
							|  |  |  |   const chrome = await playwright.chromium.launch({ channel: 'chrome' }); | 
					
						
							|  |  |  |   const version = chrome.version(); | 
					
						
							|  |  |  |   await chrome.close(); | 
					
						
							|  |  |  |   console.log(`Found Chrome version ${version}`); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const [major] = version.split('.'); | 
					
						
							| 
									
										
										
										
											2023-07-27 05:53:45 -07:00
										 |  |  |   const downloadsInfo = JSON.parse(execSync(`curl https://googlechromelabs.github.io/chrome-for-testing/latest-versions-per-milestone-with-downloads.json --silent`).toString('utf-8')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let currentPlatform = ''; | 
					
						
							|  |  |  |   if (process.platform === 'darwin') | 
					
						
							|  |  |  |     currentPlatform = process.arch === 'arm64' ? 'mac-arm64' : 'mac-x64'; | 
					
						
							|  |  |  |   else if (process.platform === 'linux') | 
					
						
							|  |  |  |     currentPlatform = 'linux64'; | 
					
						
							|  |  |  |   else  | 
					
						
							|  |  |  |     currentPlatform = 'win64'; | 
					
						
							|  |  |  |   const chromeDriverURL = downloadsInfo.milestones[major].downloads.chromedriver.find(({ platform, url }) => platform === currentPlatform).url; | 
					
						
							|  |  |  |   console.log(`Found ChromeDriver download URL: ${chromeDriverURL}`); | 
					
						
							| 
									
										
										
										
											2021-11-18 15:32:09 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   const zip = path.join(dir, 'chromedriver.zip'); | 
					
						
							| 
									
										
										
										
											2023-07-27 05:53:45 -07:00
										 |  |  |   execSync(`curl ${chromeDriverURL} --output ${zip} --silent`); | 
					
						
							| 
									
										
										
										
											2021-11-18 15:32:09 -08:00
										 |  |  |   console.log(`Downloaded ${zip}`); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-27 22:25:57 +02:00
										 |  |  |   execSync(`unzip -j ${zip}`, { cwd: dir }); | 
					
						
							| 
									
										
										
										
											2021-11-18 15:32:09 -08:00
										 |  |  |   console.log(`Unzipped ${zip}`); | 
					
						
							| 
									
										
										
										
											2023-07-27 22:25:57 +02:00
										 |  |  |   fs.rmSync(zip); | 
					
						
							| 
									
										
										
										
											2021-11-18 15:32:09 -08:00
										 |  |  | })(); |