@@ -74,7 +74,7 @@ def get_driver() -> webdriver.Chrome:
7474 )
7575
7676
77- def _export_to_png (exported_asset : ExportedAsset ) -> None :
77+ def _export_to_png (exported_asset : ExportedAsset , max_height_pixels : Optional [ int ] = None ) -> None :
7878 """
7979 Exporting an Insight means:
8080 1. Loading the Insight from the web app in a dedicated rendering mode
@@ -150,7 +150,9 @@ def _export_to_png(exported_asset: ExportedAsset) -> None:
150150
151151 logger .info ("exporting_asset" , asset_id = exported_asset .id , render_url = url_to_render )
152152
153- _screenshot_asset (image_path , url_to_render , screenshot_width , wait_for_css_selector , screenshot_height )
153+ _screenshot_asset (
154+ image_path , url_to_render , screenshot_width , wait_for_css_selector , screenshot_height , max_height_pixels
155+ )
154156
155157 with open (image_path , "rb" ) as image_file :
156158 image_data = image_file .read ()
@@ -181,6 +183,7 @@ def _screenshot_asset(
181183 screenshot_width : ScreenWidth ,
182184 wait_for_css_selector : CSSSelector ,
183185 screenshot_height : int = 600 ,
186+ max_height_pixels : Optional [int ] = None ,
184187) -> None :
185188 driver : Optional [webdriver .Chrome ] = None
186189 try :
@@ -238,6 +241,15 @@ def _screenshot_asset(
238241 """
239242 )
240243
244+ if max_height_pixels and height > max_height_pixels :
245+ logger .warning (
246+ "screenshot_height_capped" ,
247+ original_height = height ,
248+ capped_height = max_height_pixels ,
249+ url = url_to_render ,
250+ )
251+ height = max_height_pixels
252+
241253 # For example funnels use a table that can get very wide, so try to get its width
242254 # For replay players, check for player width
243255 width = driver .execute_script (
@@ -280,6 +292,15 @@ def _screenshot_asset(
280292 """
281293 )
282294
295+ if max_height_pixels and final_height > max_height_pixels :
296+ logger .warning (
297+ "screenshot_final_height_capped" ,
298+ original_final_height = final_height ,
299+ capped_height = max_height_pixels ,
300+ url = url_to_render ,
301+ )
302+ final_height = max_height_pixels
303+
283304 # Set final window size
284305 driver .set_window_size (width , final_height + HEIGHT_OFFSET )
285306 driver .save_screenshot (image_path )
@@ -302,7 +323,7 @@ def _screenshot_asset(
302323 driver .quit ()
303324
304325
305- def export_image (exported_asset : ExportedAsset ) -> None :
326+ def export_image (exported_asset : ExportedAsset , max_height_pixels : Optional [ int ] = None ) -> None :
306327 with posthoganalytics .new_context ():
307328 posthoganalytics .tag ("team_id" , exported_asset .team_id if exported_asset else "unknown" )
308329 posthoganalytics .tag ("asset_id" , exported_asset .id if exported_asset else "unknown" )
@@ -324,7 +345,7 @@ def export_image(exported_asset: ExportedAsset) -> None:
324345
325346 if exported_asset .export_format == "image/png" :
326347 with EXPORT_TIMER .labels (type = "image" ).time ():
327- _export_to_png (exported_asset )
348+ _export_to_png (exported_asset , max_height_pixels = max_height_pixels )
328349 EXPORT_SUCCEEDED_COUNTER .labels (type = "image" ).inc ()
329350 else :
330351 raise NotImplementedError (
0 commit comments