@@ -3,8 +3,16 @@ module.exports = { computeDownloadUrls, resolveDownloadPath, getLastChromedriver
33const got = require ( 'got' ) ;
44const util = require ( 'util' ) ;
55const { isSelenium4 } = require ( './isSelenium4' ) ;
6- const { detectBrowserPlatform , resolveBuildId } = require ( '@puppeteer/browsers' ) ;
6+ const { resolveBuildId } = require ( '@puppeteer/browsers' ) ;
77const { validateMajorVersionPrefix, getVersionWithZeroedPatchPart } = require ( './validation' ) ;
8+ const {
9+ detectBrowserPlatformCustom,
10+ getArhType,
11+ getChromiumEdgeDriverArchitectureOld,
12+ getChromeDriverArchitectureOld,
13+ getIeDriverArchitectureOld,
14+ getFirefoxDriverArchitectureOld,
15+ } = require ( './platformDetection' ) ;
816const axios = require ( 'axios' ) ;
917
1018const urls = {
@@ -59,11 +67,11 @@ async function computeDownloadUrls(options) {
5967 if ( opts . drivers . chrome . version === 'latest' && ! opts . drivers . chrome . fullURL ) {
6068 opts . drivers . chrome . version = await resolveBuildId (
6169 'chromedriver' ,
62- detectBrowserPlatform ( ) ,
70+ detectBrowserPlatformCustom ( opts . drivers . chrome . arch ) ,
6371 opts . drivers . chrome . channel ? opts . drivers . chrome . channel : 'stable'
6472 ) ;
6573 downloadUrls . chrome = resolveDownloadUrl (
66- detectBrowserPlatform ( ) ,
74+ detectBrowserPlatformCustom ( opts . drivers . chrome . arch ) ,
6775 opts . drivers . chrome . version ,
6876 opts . drivers . chrome . baseURL
6977 ) ;
@@ -83,7 +91,7 @@ async function computeDownloadUrls(options) {
8391 ) {
8492 const url = lastVersionFromMajor . downloads . chromedriver
8593 . map ( ( m ) => {
86- if ( m . platform === detectBrowserPlatform ( ) ) {
94+ if ( m . platform === detectBrowserPlatformCustom ( opts . drivers . chrome . arch ) ) {
8795 return m . url ;
8896 }
8997 } )
@@ -97,11 +105,11 @@ async function computeDownloadUrls(options) {
97105
98106 opts . drivers . chrome . version = await resolveBuildId (
99107 'chromedriver' ,
100- detectBrowserPlatform ( ) ,
108+ detectBrowserPlatformCustom ( opts . drivers . chrome . arch ) ,
101109 opts . drivers . chrome . channel ? opts . drivers . chrome . channel : 'stable'
102110 ) ;
103111 downloadUrls . chrome = resolveDownloadUrl (
104- detectBrowserPlatform ( ) ,
112+ detectBrowserPlatformCustom ( opts . drivers . chrome . arch ) ,
105113 opts . drivers . chrome . version ,
106114 opts . drivers . chrome . baseURL
107115 ) ;
@@ -111,11 +119,11 @@ async function computeDownloadUrls(options) {
111119
112120 opts . drivers . chrome . version = await resolveBuildId (
113121 'chromedriver' ,
114- detectBrowserPlatform ( ) ,
122+ detectBrowserPlatformCustom ( opts . drivers . chrome . arch ) ,
115123 opts . drivers . chrome . channel ? opts . drivers . chrome . channel : 'stable'
116124 ) ;
117125 downloadUrls . chrome = resolveDownloadUrl (
118- detectBrowserPlatform ( ) ,
126+ detectBrowserPlatformCustom ( opts . drivers . chrome . arch ) ,
119127 opts . drivers . chrome . version ,
120128 opts . drivers . chrome . baseURL
121129 ) ;
@@ -143,7 +151,7 @@ async function computeDownloadUrls(options) {
143151 urls . chrome ,
144152 opts . drivers . chrome . baseURL ,
145153 opts . drivers . chrome . version ,
146- getChromeDriverArchitecture ( opts . drivers . chrome . arch , opts . drivers . chrome . version )
154+ getChromeDriverArchitectureOld ( opts . drivers . chrome . arch , opts . drivers . chrome . version )
147155 ) ;
148156 }
149157 }
@@ -154,7 +162,7 @@ async function computeDownloadUrls(options) {
154162 urls . ie ,
155163 opts . drivers . ie . baseURL ,
156164 opts . drivers . ie . version . slice ( 0 , opts . drivers . ie . version . lastIndexOf ( '.' ) ) ,
157- getIeDriverArchitecture ( opts . drivers . ie . arch ) ,
165+ getIeDriverArchitectureOld ( opts . drivers . ie . arch ) ,
158166 opts . drivers . ie . version
159167 ) ;
160168 }
@@ -168,7 +176,7 @@ async function computeDownloadUrls(options) {
168176 `v${ opts . drivers . firefox . version } ` ,
169177 'geckodriver' ,
170178 `v${ opts . drivers . firefox . version } ` ,
171- getFirefoxDriverArchitecture ( opts . drivers . firefox . arch )
179+ getFirefoxDriverArchitectureOld ( opts . drivers . firefox . arch )
172180 ) ;
173181 }
174182 if ( opts . drivers . edge ) {
@@ -186,73 +194,12 @@ async function computeDownloadUrls(options) {
186194 urls . chromiumedge ,
187195 opts . drivers . chromiumedge . baseURL ,
188196 opts . drivers . chromiumedge . version ,
189- getChromiumEdgeDriverArchitecture ( opts . drivers . chromiumedge . arch , opts . drivers . chromiumedge . version )
197+ getChromiumEdgeDriverArchitectureOld ( opts . drivers . chromiumedge . arch , opts . drivers . chromiumedge . version )
190198 ) ;
191199 }
192200 return downloadUrls ;
193201}
194202
195- function getChromeDriverArchitecture ( wantedArchitecture , version ) {
196- let platform ;
197-
198- if ( process . platform === 'linux' ) {
199- platform = 'linux64' ;
200- } else if ( process . platform === 'darwin' ) {
201- if ( process . arch === 'arm64' ) {
202- const [ major ] = version . split ( '.' ) ;
203- platform = parseInt ( major , 10 ) > 105 ? 'mac_arm64' : 'mac64_m1' ;
204- } else {
205- platform = 'mac64' ;
206- }
207- } else {
208- platform = 'win32' ;
209- }
210-
211- return platform ;
212- }
213-
214- function getIeDriverArchitecture ( wanted ) {
215- let platform ;
216-
217- if ( wanted === 'ia32' ) {
218- platform = 'Win32' ;
219- } else {
220- platform = 'x64' ;
221- }
222-
223- return platform ;
224- }
225-
226- function getFirefoxDriverArchitecture ( wantedArchitecture ) {
227- const extension = '.tar.gz' ;
228-
229- switch ( process . platform ) {
230- case 'linux' :
231- return getLinuxFirefoxDriverArchitecture ( extension , wantedArchitecture ) ;
232- case 'darwin' :
233- return getMacFirefoxDriverArchitecture ( extension ) ;
234- case 'win32' :
235- return getWindowsFirefoxDriverArchitecture ( wantedArchitecture ) ;
236- default :
237- throw new Error ( 'No Firefox driver is available for platform "' + process . platform + '"' ) ;
238- }
239- }
240-
241- function getLinuxFirefoxDriverArchitecture ( extension , wantedArchitecture = 'x64' ) {
242- const arch = wantedArchitecture === 'x64' ? '64' : '32' ;
243- return 'linux' + arch + extension ;
244- }
245-
246- function getMacFirefoxDriverArchitecture ( extension ) {
247- return 'macos' + ( process . arch === 'arm64' ? '-aarch64' : '' ) + extension ;
248- }
249-
250- function getWindowsFirefoxDriverArchitecture ( wantedArchitecture = '64' ) {
251- const arch = wantedArchitecture . substr ( - 2 ) === '64' ? '64' : '32' ;
252-
253- return `win${ arch } .zip` ;
254- }
255-
256203const microsoftEdgeReleases = require ( './microsoft-edge-releases' ) ;
257204
258205function getEdgeDriverUrl ( version ) {
@@ -266,33 +213,12 @@ function getEdgeDriverUrl(version) {
266213 return release . url ;
267214}
268215
269- function getChromiumEdgeDriverArchitecture ( wantedArchitecture , version ) {
270- let platform ;
271-
272- if ( process . platform === 'linux' ) {
273- platform = 'linux64' ;
274- } else if ( process . platform === 'darwin' ) {
275- if ( process . arch === 'arm64' ) {
276- const [ major ] = version . split ( '.' ) ;
277- platform = parseInt ( major , 10 ) > 104 ? 'mac64_m1' : 'mac64' ;
278- } else {
279- platform = 'mac64' ;
280- }
281- } else if ( wantedArchitecture === 'x32' ) {
282- platform = 'win32' ;
283- } else {
284- platform = 'win64' ;
285- }
286-
287- return platform ;
288- }
289-
290216async function chromiumEdgeBundleAvailable ( opts ) {
291217 const url = util . format (
292218 urls . chromiumedge ,
293219 opts . drivers . chromiumedge . baseURL ,
294220 opts . drivers . chromiumedge . version ,
295- getChromiumEdgeDriverArchitecture ( opts . drivers . chromiumedge . platform )
221+ getChromiumEdgeDriverArchitectureOld ( opts . drivers . chromiumedge . platform )
296222 ) ;
297223 try {
298224 await got . head ( url , { timeout : 10000 } ) ;
@@ -362,23 +288,8 @@ function resolveDownloadUrl(
362288 return `${ baseUrl } /${ resolveDownloadPath ( platform , buildId ) . join ( '/' ) } ` ;
363289}
364290
365- function folder ( platform ) {
366- switch ( platform ) {
367- case 'linux' :
368- return 'linux64' ;
369- case 'mac_arm' :
370- return 'mac-arm64' ;
371- case 'mac' :
372- return 'mac-x64' ;
373- case 'win32' :
374- return 'win32' ;
375- case 'win64' :
376- return 'win64' ;
377- }
378- }
379-
380291function resolveDownloadPath ( platform , buildId ) {
381- return [ buildId , folder ( platform ) , `chromedriver-${ folder ( platform ) } .zip` ] ;
292+ return [ buildId , getArhType ( platform ) , `chromedriver-${ getArhType ( platform ) } .zip` ] ;
382293}
383294
384295async function getLastChromedriverVersionFromMajor ( version ) {
0 commit comments