@@ -73,6 +73,7 @@ import {
7373 handle_browser_cookies ,
7474 handle_browser_open ,
7575 handle_browser_reload ,
76+ handle_browser_screenshot ,
7677 handle_browser_sessions ,
7778 handle_browser_snapshot ,
7879 handle_browser_status ,
@@ -216,6 +217,39 @@ describe('commands/browser', ()=>{
216217 ) ;
217218 } ) ;
218219
220+ it ( 'captures a screenshot for an active browser session' , async ( ) => {
221+ mocks . send_command . mockResolvedValue ( {
222+ success : true ,
223+ data : {
224+ full_page : true ,
225+ mime_type : 'image/png' ,
226+ path : '/tmp/browser-shot.png' ,
227+ } ,
228+ } ) ;
229+
230+ await handle_browser_screenshot ( '/tmp/browser-shot.png' , {
231+ fullPage : true ,
232+ session : 'shop' ,
233+ } ) ;
234+
235+ expect ( mocks . send_command ) . toHaveBeenCalledWith (
236+ 'shop' ,
237+ expect . objectContaining ( {
238+ action : 'screenshot' ,
239+ params : {
240+ base64 : false ,
241+ full_page : true ,
242+ path : '/tmp/browser-shot.png' ,
243+ } ,
244+ } ) ,
245+ { daemon_dir : undefined , timeout_ms : undefined }
246+ ) ;
247+ expect ( mocks . print ) . toHaveBeenCalledWith (
248+ '/tmp/browser-shot.png' ,
249+ { output : undefined }
250+ ) ;
251+ } ) ;
252+
219253 it ( 'rejects invalid snapshot depth before sending the command' , async ( ) => {
220254 await expect ( handle_browser_snapshot ( { depth : 'abc' , session : 'shop' } ) ) . rejects . toThrow (
221255 'fail:Snapshot depth must be a non-negative integer.'
@@ -454,6 +488,52 @@ describe('commands/browser', ()=>{
454488 ) ;
455489 } ) ;
456490
491+ it ( 'parses screenshot flags and forwards the screenshot params' , async ( ) => {
492+ mocks . send_command . mockResolvedValue ( {
493+ success : true ,
494+ data : {
495+ base64 : 'aW1hZ2U=' ,
496+ full_page : true ,
497+ mime_type : 'image/png' ,
498+ path : '/tmp/browser-shot.png' ,
499+ } ,
500+ } ) ;
501+ const command = create_browser_command ( ) ;
502+ command . exitOverride ( ) ;
503+
504+ await command . parseAsync ( [
505+ 'screenshot' ,
506+ '/tmp/browser-shot.png' ,
507+ '--session' ,
508+ 'shop' ,
509+ '--full-page' ,
510+ '--base64' ,
511+ '--json' ,
512+ ] , { from : 'user' } ) ;
513+
514+ expect ( mocks . send_command ) . toHaveBeenCalledWith (
515+ 'shop' ,
516+ expect . objectContaining ( {
517+ action : 'screenshot' ,
518+ params : {
519+ base64 : true ,
520+ full_page : true ,
521+ path : '/tmp/browser-shot.png' ,
522+ } ,
523+ } ) ,
524+ { daemon_dir : undefined , timeout_ms : undefined }
525+ ) ;
526+ expect ( mocks . print ) . toHaveBeenCalledWith (
527+ {
528+ base64 : 'aW1hZ2U=' ,
529+ full_page : true ,
530+ mime_type : 'image/png' ,
531+ path : '/tmp/browser-shot.png' ,
532+ } ,
533+ { json : true , output : undefined , pretty : undefined }
534+ ) ;
535+ } ) ;
536+
457537 it ( 'rejects open-only flags on status through browser-group parsing' , async ( ) => {
458538 const command = create_browser_command ( ) ;
459539 command . exitOverride ( ) ;
@@ -498,6 +578,20 @@ describe('commands/browser', ()=>{
498578 expect ( mocks . send_command ) . not . toHaveBeenCalled ( ) ;
499579 } ) ;
500580
581+ it ( 'rejects screenshot-only flags outside the screenshot command' , async ( ) => {
582+ const command = create_browser_command ( ) ;
583+ command . exitOverride ( ) ;
584+
585+ await expect ( command . parseAsync ( [
586+ 'status' ,
587+ '--full-page' ,
588+ ] , { from : 'user' } ) ) . rejects . toThrow (
589+ 'fail:--full-page is not supported by "brightdata browser status".'
590+ ) ;
591+
592+ expect ( mocks . send_command ) . not . toHaveBeenCalled ( ) ;
593+ } ) ;
594+
501595 it ( 'rejects not-yet-implemented global flags on open' , async ( ) => {
502596 const command = create_browser_command ( ) ;
503597 command . exitOverride ( ) ;
0 commit comments