@@ -79,7 +79,7 @@ export enum Mode {
7979}
8080
8181type Keys < T > = {
82- [ K in keyof T ] ?: T [ K ] extends object ? ( T [ K ] extends any [ ] ? string : Keys < T [ K ] > ) : string ;
82+ [ K in keyof T ] - ?: T [ K ] extends object ? ( T [ K ] extends any [ ] ? string : Keys < NonNullable < T [ K ] > > ) : string ;
8383} ;
8484
8585const envConfig : Record < Mode , Keys < RenderingConfig > > = {
@@ -101,13 +101,18 @@ const envConfig: Record<Mode, Keys<RenderingConfig>> = {
101101 mode : 'RENDERING_CLUSTERING_MODE' ,
102102 maxConcurrency : 'RENDERING_CLUSTERING_MAX_CONCURRENCY' ,
103103 timeout : 'RENDERING_CLUSTERING_TIMEOUT' ,
104+ monitor : 'RENDERING_CLUSTERING_MONITOR' ,
104105 } ,
105106 verboseLogging : 'RENDERING_VERBOSE_LOGGING' ,
106107 dumpio : 'RENDERING_DUMPIO' ,
107108 timingMetrics : 'RENDERING_TIMING_METRICS' ,
108109 tracing : {
109110 url : 'RENDERING_TRACING_URL' ,
111+ serviceName : 'RENDERING_TRACING_SERVICE_NAME' ,
110112 } ,
113+ headed : 'RENDERING_HEADED' ,
114+ emulateNetworkConditions : 'RENDERING_EMULATE_NETWORK_CONDITIONS' ,
115+ networkConditions : 'RENDERING_NETWORK_CONDITIONS' ,
111116 } ,
112117 plugin : {
113118 chromeBin : 'GF_PLUGIN_RENDERING_CHROME_BIN' ,
@@ -127,25 +132,30 @@ const envConfig: Record<Mode, Keys<RenderingConfig>> = {
127132 mode : 'GF_PLUGIN_RENDERING_CLUSTERING_MODE' ,
128133 maxConcurrency : 'GF_PLUGIN_RENDERING_CLUSTERING_MAX_CONCURRENCY' ,
129134 timeout : 'GF_PLUGIN_RENDERING_CLUSTERING_TIMEOUT' ,
135+ monitor : 'GF_PLUGIN_RENDERING_CLUSTERING_MONITOR' ,
130136 } ,
131137 verboseLogging : 'GF_PLUGIN_RENDERING_VERBOSE_LOGGING' ,
132138 dumpio : 'GF_PLUGIN_RENDERING_DUMPIO' ,
133139 timingMetrics : 'GF_PLUGIN_RENDERING_TIMING_METRICS' ,
134140 tracing : {
135141 url : 'GF_PLUGIN_RENDERING_TRACING_URL' ,
142+ serviceName : 'GF_PLUGIN_RENDERING_TRACING_SERVICE_NAME' ,
136143 } ,
144+ headed : 'GF_PLUGIN_RENDERING_HEADED' ,
145+ emulateNetworkConditions : 'GF_PLUGIN_RENDERING_EMULATE_NETWORK_CONDITIONS' ,
146+ networkConditions : 'GF_PLUGIN_RENDERING_NETWORK_CONDITIONS' ,
137147 } ,
138148} ;
139149
140150export function populateRenderingConfigFromEnv ( config : RenderingConfig , env : NodeJS . ProcessEnv , mode : Mode ) {
141151 const envKeys = envConfig [ mode ] ;
142152
143- if ( env [ envKeys . chromeBin ! ] ) {
144- config . chromeBin = env [ envKeys . chromeBin ! ] ;
153+ if ( env [ envKeys . chromeBin ] ) {
154+ config . chromeBin = env [ envKeys . chromeBin ] ;
145155 }
146156
147- if ( env [ envKeys . args ! ] ) {
148- const args = env [ envKeys . args ! ] as string ;
157+ if ( env [ envKeys . args ] ) {
158+ const args = env [ envKeys . args ] as string ;
149159 if ( args . length > 0 ) {
150160 const argsList = args . split ( ',' ) ;
151161 if ( argsList . length > 0 ) {
@@ -154,77 +164,95 @@ export function populateRenderingConfigFromEnv(config: RenderingConfig, env: Nod
154164 }
155165 }
156166
157- if ( env [ envKeys . ignoresHttpsErrors ! ] ) {
158- config . ignoresHttpsErrors = env [ envKeys . ignoresHttpsErrors ! ] === 'true' ;
167+ if ( env [ envKeys . ignoresHttpsErrors ] ) {
168+ config . ignoresHttpsErrors = env [ envKeys . ignoresHttpsErrors ] === 'true' ;
159169 }
160170
161- if ( env [ envKeys . timezone ! ] ) {
162- config . timezone = env [ envKeys . timezone ! ] ;
171+ if ( env [ envKeys . timezone ] ) {
172+ config . timezone = env [ envKeys . timezone ] ;
163173 } else if ( env [ 'TZ' ] ) {
164174 config . timezone = env [ 'TZ' ] ;
165175 }
166176
167- if ( env [ envKeys . acceptLanguage ! ] ) {
168- config . acceptLanguage = env [ envKeys . acceptLanguage ! ] ;
177+ if ( env [ envKeys . acceptLanguage ] ) {
178+ config . acceptLanguage = env [ envKeys . acceptLanguage ] ;
169179 }
170180
171- if ( env [ envKeys . width ! ] ) {
172- config . width = parseInt ( env [ envKeys . width ! ] as string , 10 ) ;
181+ if ( env [ envKeys . width ] ) {
182+ config . width = parseInt ( env [ envKeys . width ] as string , 10 ) ;
173183 }
174184
175- if ( env [ envKeys . height ! ] ) {
176- config . height = parseInt ( env [ envKeys . height ! ] as string , 10 ) ;
185+ if ( env [ envKeys . height ] ) {
186+ config . height = parseInt ( env [ envKeys . height ] as string , 10 ) ;
177187 }
178188
179- if ( env [ envKeys . deviceScaleFactor ! ] ) {
180- config . deviceScaleFactor = parseFloat ( env [ envKeys . deviceScaleFactor ! ] as string ) ;
189+ if ( env [ envKeys . deviceScaleFactor ] ) {
190+ config . deviceScaleFactor = parseFloat ( env [ envKeys . deviceScaleFactor ] as string ) ;
181191 }
182192
183- if ( env [ envKeys . maxWidth ! ] ) {
184- config . maxWidth = parseInt ( env [ envKeys . maxWidth ! ] as string , 10 ) ;
193+ if ( env [ envKeys . maxWidth ] ) {
194+ config . maxWidth = parseInt ( env [ envKeys . maxWidth ] as string , 10 ) ;
185195 }
186196
187- if ( env [ envKeys . maxHeight ! ] ) {
188- config . maxHeight = parseInt ( env [ envKeys . maxHeight ! ] as string , 10 ) ;
197+ if ( env [ envKeys . maxHeight ] ) {
198+ config . maxHeight = parseInt ( env [ envKeys . maxHeight ] as string , 10 ) ;
189199 }
190200
191- if ( env [ envKeys . maxDeviceScaleFactor ! ] ) {
192- config . maxDeviceScaleFactor = parseFloat ( env [ envKeys . maxDeviceScaleFactor ! ] as string ) ;
201+ if ( env [ envKeys . maxDeviceScaleFactor ] ) {
202+ config . maxDeviceScaleFactor = parseFloat ( env [ envKeys . maxDeviceScaleFactor ] as string ) ;
193203 }
194204
195- if ( env [ envKeys . pageZoomLevel ! ] ) {
196- config . pageZoomLevel = parseFloat ( env [ envKeys . pageZoomLevel ! ] as string ) ;
205+ if ( env [ envKeys . pageZoomLevel ] ) {
206+ config . pageZoomLevel = parseFloat ( env [ envKeys . pageZoomLevel ] as string ) ;
197207 }
198208
199- if ( env [ envKeys . mode ! ] ) {
200- config . mode = env [ envKeys . mode ! ] as string ;
209+ if ( env [ envKeys . mode ] ) {
210+ config . mode = env [ envKeys . mode ] as string ;
201211 }
202212
203- if ( env [ envKeys . clustering ? .mode ! ] ) {
204- config . clustering . mode = env [ envKeys . clustering ? .mode ! ] as string ;
213+ if ( env [ envKeys . clustering . mode ] ) {
214+ config . clustering . mode = env [ envKeys . clustering . mode ] as string ;
205215 }
206-
207- if ( env [ envKeys . clustering ?. maxConcurrency ! ] ) {
208- config . clustering . maxConcurrency = parseInt ( env [ envKeys . clustering ?. maxConcurrency ! ] as string , 10 ) ;
216+ if ( env [ envKeys . clustering . maxConcurrency ] ) {
217+ config . clustering . maxConcurrency = parseInt ( env [ envKeys . clustering . maxConcurrency ] as string , 10 ) ;
218+ }
219+ if ( env [ envKeys . clustering . timeout ] ) {
220+ config . clustering . timeout = parseInt ( env [ envKeys . clustering . timeout ] as string , 10 ) ;
221+ }
222+ if ( env [ envKeys . clustering . monitor ] ) {
223+ config . clustering . monitor = env [ envKeys . clustering . monitor ] === 'true' ;
209224 }
210225
211- if ( env [ envKeys . clustering ?. timeout ! ] ) {
212- config . clustering . timeout = parseInt ( env [ envKeys . clustering ?. timeout ! ] as string , 10 ) ;
226+ if ( env [ envKeys . verboseLogging ] ) {
227+ config . verboseLogging = env [ envKeys . verboseLogging ] === 'true' ;
213228 }
214229
215- if ( env [ envKeys . verboseLogging ! ] ) {
216- config . verboseLogging = env [ envKeys . verboseLogging ! ] === 'true' ;
230+ if ( env [ envKeys . dumpio ] ) {
231+ config . dumpio = env [ envKeys . dumpio ] === 'true' ;
217232 }
218233
219- if ( env [ envKeys . dumpio ! ] ) {
220- config . dumpio = env [ envKeys . dumpio ! ] === 'true' ;
234+ if ( env [ envKeys . timingMetrics ] ) {
235+ config . timingMetrics = env [ envKeys . timingMetrics ] === 'true' ;
221236 }
222237
223- if ( env [ envKeys . timingMetrics ! ] ) {
224- config . timingMetrics = env [ envKeys . timingMetrics ! ] === 'true' ;
238+ if ( env [ envKeys . tracing . url ] ) {
239+ config . tracing . url = env [ envKeys . tracing . url ] as string ;
240+ }
241+ if ( env [ envKeys . tracing . serviceName ] ) {
242+ config . tracing . serviceName = env [ envKeys . tracing . serviceName ] as string ;
225243 }
226244
227- if ( env [ envKeys . tracing ?. url ! ] ) {
228- config . tracing . url = env [ envKeys . tracing ?. url ! ] as string ;
245+ if ( env [ envKeys . headed ] ) {
246+ config . headed = env [ envKeys . headed ] === 'true' ;
247+ }
248+ if ( env [ envKeys . emulateNetworkConditions ] ) {
249+ config . emulateNetworkConditions = env [ envKeys . emulateNetworkConditions ] === 'true' ;
250+ }
251+ if ( env [ envKeys . networkConditions ] ) {
252+ try {
253+ config . networkConditions = JSON . parse ( env [ envKeys . networkConditions ] as string ) ;
254+ } catch ( e ) {
255+ throw new Error ( `Invalid network conditions JSON: ${ env [ envKeys . networkConditions ] } ` ) ;
256+ }
229257 }
230258}
0 commit comments