@@ -486,6 +486,21 @@ def _browser_context(
486486 is_flag = True ,
487487 help = "Leave servers running when script finishes" ,
488488)
489+ @click .option (
490+ "--har" ,
491+ is_flag = True ,
492+ help = "Save all requests to trace.har file" ,
493+ )
494+ @click .option (
495+ "--har-zip" ,
496+ is_flag = True ,
497+ help = "Save all requests to trace.har.zip file" ,
498+ )
499+ @click .option (
500+ "--har-file" ,
501+ type = click .Path (file_okay = True , writable = True , dir_okay = False ),
502+ help = "Path to HAR file to save all requests" ,
503+ )
489504def multi (
490505 config ,
491506 auth ,
@@ -506,6 +521,9 @@ def multi(
506521 auth_username ,
507522 auth_password ,
508523 leave_server ,
524+ har ,
525+ har_zip ,
526+ har_file ,
509527):
510528 """
511529 Take multiple screenshots, defined by a YAML file
@@ -524,6 +542,11 @@ def multi(
524542 For full YAML syntax documentation, see:
525543 https://shot-scraper.datasette.io/en/stable/multi.html
526544 """
545+ if (har or har_zip ) and not har_file :
546+ har_file = filename_for_url (
547+ "trace" , ext = "har.zip" if har_zip else "har" , file_exists = os .path .exists
548+ )
549+
527550 scale_factor = normalize_scale_factor (retina , scale_factor )
528551 shots = yaml .safe_load (config )
529552 server_processes = []
@@ -543,6 +566,7 @@ def multi(
543566 reduced_motion = reduced_motion ,
544567 auth_username = auth_username ,
545568 auth_password = auth_password ,
569+ record_har_path = har_file or None ,
546570 )
547571 try :
548572 for shot in shots :
@@ -599,11 +623,16 @@ def multi(
599623 browser_obj .close ()
600624 if leave_server :
601625 for process , details in server_processes :
602- print ("Leaving server PID:" , process .pid , " details:" , details )
626+ click .echo (
627+ f"Leaving server PID: { process .pid } details: { details } " ,
628+ err = True ,
629+ )
603630 else :
604631 if server_processes :
605632 for process , _ in server_processes :
606633 process .kill ()
634+ if har_file and not silent :
635+ click .echo (f"Wrote to HAR file: { har_file } " , err = True )
607636
608637
609638@cli .command ()
0 commit comments