1+ import fs from 'fs' ;
12import { Command } from 'commander' ;
23import { post } from '../utils/client' ;
34import { ensure_authenticated } from '../utils/auth' ;
45import { resolve } from '../utils/config' ;
56import { start as start_spinner } from '../utils/spinner' ;
6- import { print , success , fail } from '../utils/output' ;
7+ import { print , success , fail , info } from '../utils/output' ;
78import type {
89 Scrape_format ,
910 Scrape_request ,
@@ -54,11 +55,11 @@ const handle_scrape = async(url: string, opts: Scrape_opts)=>{
5455 const req = build_request ( url , zone , fmt , opts ) ;
5556 const spinner = start_spinner ( `Scraping ${ url } ...` ) ;
5657 try {
57- const result = await post < string | Scrape_response_json | Scrape_async_response > (
58+ const result = await post < string | Buffer | Scrape_response_json | Scrape_async_response > (
5859 api_key ,
5960 ENDPOINT ,
6061 req ,
61- { timing : opts . timing }
62+ { timing : opts . timing , raw_buffer : fmt == 'screenshot' }
6263 ) ;
6364 spinner . stop ( ) ;
6465 if ( opts . async )
@@ -67,6 +68,13 @@ const handle_scrape = async(url: string, opts: Scrape_opts)=>{
6768 success ( `Async job submitted. Response ID: ${ async_res . response_id } ` ) ;
6869 return ;
6970 }
71+ if ( fmt == 'screenshot' )
72+ {
73+ const out = opts . output ?? 'screenshot.png' ;
74+ fs . writeFileSync ( out , result as Buffer ) ;
75+ info ( `Output written to ${ out } ` ) ;
76+ return ;
77+ }
7078 const print_opts = { json : opts . json , pretty : opts . pretty , output : opts . output } ;
7179 if ( fmt == 'json' )
7280 {
0 commit comments