@@ -4,8 +4,11 @@ import os from 'node:os'
4
4
import cp from 'node:child_process'
5
5
import { format } from 'node:util'
6
6
7
+ import fetch , { type RequestInit } from 'node-fetch'
7
8
import { XMLParser } from 'fast-xml-parser'
8
9
import { BlobReader , BlobWriter , ZipReader } from '@zip.js/zip.js'
10
+ import { HttpsProxyAgent } from 'https-proxy-agent'
11
+ import { HttpProxyAgent } from 'http-proxy-agent'
9
12
10
13
import findEdgePath from './finder.js'
11
14
import { TAGGED_VERSIONS , EDGE_PRODUCTS_API , EDGEDRIVER_BUCKET , TAGGED_VERSION_URL , LATEST_RELEASE_URL , DOWNLOAD_URL , BINARY_FILE , log } from './constants.js'
@@ -20,6 +23,13 @@ interface ProductAPIResponse {
20
23
} [ ]
21
24
}
22
25
26
+ const fetchOpts : RequestInit = { }
27
+ if ( process . env . HTTPS_PROXY ) {
28
+ fetchOpts . agent = new HttpsProxyAgent ( process . env . HTTPS_PROXY )
29
+ } else if ( process . env . HTTP_PROXY ) {
30
+ fetchOpts . agent = new HttpProxyAgent ( process . env . HTTP_PROXY )
31
+ }
32
+
23
33
export async function download (
24
34
edgeVersion : string = process . env . EDGEDRIVER_VERSION ,
25
35
cacheDir : string = process . env . EDGEDRIVER_CACHE_DIR || os . tmpdir ( )
@@ -55,7 +65,7 @@ async function downloadDriver(version: string) {
55
65
try {
56
66
const downloadUrl = format ( DOWNLOAD_URL , version , getNameByArchitecture ( ) )
57
67
log . info ( `Downloading Edgedriver from ${ downloadUrl } ` )
58
- const res = await fetch ( downloadUrl )
68
+ const res = await fetch ( downloadUrl , fetchOpts )
59
69
60
70
if ( ! res . body || ! res . ok || res . status !== 200 ) {
61
71
throw new Error ( `Failed to download binary from ${ downloadUrl } (statusCode ${ res . status } )` )
@@ -75,6 +85,7 @@ async function downloadDriver(version: string) {
75
85
: 'linux'
76
86
log . info ( `Attempt to fetch latest v${ majorVersion } for ${ platform } from ${ EDGEDRIVER_BUCKET } ` )
77
87
const versions = await fetch ( EDGEDRIVER_BUCKET , {
88
+ ...fetchOpts ,
78
89
headers : {
79
90
accept : '*/*' ,
80
91
'accept-language' : 'en-US,en;q=0.9' ,
@@ -95,11 +106,11 @@ async function downloadDriver(version: string) {
95
106
}
96
107
97
108
log . info ( `Downloading alternative Edgedriver version from ${ alternativeDownloadUrl } ` )
98
- const versionResponse = await fetch ( alternativeDownloadUrl )
109
+ const versionResponse = await fetch ( alternativeDownloadUrl , fetchOpts )
99
110
const alternativeVersion = sanitizeVersion ( await versionResponse . text ( ) )
100
111
const downloadUrl = format ( DOWNLOAD_URL , alternativeVersion , getNameByArchitecture ( ) )
101
112
log . info ( `Downloading Edgedriver from ${ downloadUrl } ` )
102
- const res = await fetch ( downloadUrl )
113
+ const res = await fetch ( downloadUrl , fetchOpts )
103
114
if ( ! res . body || ! res . ok || res . status !== 200 ) {
104
115
throw new Error ( `Failed to download binary from ${ downloadUrl } (statusCode ${ res . status } )` )
105
116
}
@@ -168,7 +179,7 @@ export async function fetchVersion (edgeVersion: string) {
168
179
* if browser version is a tagged version, e.g. stable, beta, dev, canary
169
180
*/
170
181
if ( TAGGED_VERSIONS . includes ( edgeVersion . toLowerCase ( ) ) ) {
171
- const apiResponse = await fetch ( EDGE_PRODUCTS_API ) . catch ( ( err ) => {
182
+ const apiResponse = await fetch ( EDGE_PRODUCTS_API , fetchOpts ) . catch ( ( err ) => {
172
183
log . error ( `Couldn't fetch version from ${ EDGE_PRODUCTS_API } : ${ err . stack } ` )
173
184
return { json : async ( ) => [ ] as ProductAPIResponse [ ] }
174
185
} )
@@ -193,7 +204,7 @@ export async function fetchVersion (edgeVersion: string) {
193
204
return productVersion
194
205
}
195
206
196
- const res = await fetch ( format ( TAGGED_VERSION_URL , edgeVersion . toUpperCase ( ) ) )
207
+ const res = await fetch ( format ( TAGGED_VERSION_URL , edgeVersion . toUpperCase ( ) ) , fetchOpts )
197
208
return sanitizeVersion ( await res . text ( ) )
198
209
}
199
210
@@ -205,7 +216,7 @@ export async function fetchVersion (edgeVersion: string) {
205
216
const [ major ] = edgeVersion . match ( MATCH_VERSION )
206
217
const url = format ( LATEST_RELEASE_URL , major . toString ( ) . toUpperCase ( ) , platform . toUpperCase ( ) )
207
218
log . info ( `Fetching latest version from ${ url } ` )
208
- const res = await fetch ( url )
219
+ const res = await fetch ( url , fetchOpts )
209
220
if ( ! res . ok || res . status !== 200 ) {
210
221
throw new Error ( `Couldn't detect version for ${ edgeVersion } ` )
211
222
}
0 commit comments