@@ -4,34 +4,35 @@ import * as chromeDriver from 'chromedriver';
44import { ThenableWebDriver , Builder , Capabilities } from 'selenium-webdriver' ;
55import { from , of , Observable } from 'rxjs' ;
66import { concatMap , map , tap } from 'rxjs/operators' ;
7+ import { OptionsInterface } from './interface/options.interface' ;
78
89export class RemoteScreenCapture {
910 public getDriver ( ) : Observable < ThenableWebDriver > {
1011 chrome . setDefaultService ( new chrome . ServiceBuilder ( chromeDriver . path ) . build ( ) ) ;
1112 return of ( new Builder ( )
12- . withCapabilities ( Capabilities . chrome ( ) . set ( 'chromeOptions' , {
13- args : [
14- `--window-size=2880,1800`
15- ]
16- } ) )
13+ . withCapabilities ( Capabilities . chrome ( ) )
1714 . setChromeOptions (
1815 new chrome . Options ( ) . headless ( ) . addExtensions ( )
1916 )
2017 . build ( )
2118 ) ;
2219 }
2320
24- public static take ( URI : string , savePath ?: string ) : Observable < string | void > {
21+ public static take ( URI : string , options ?: OptionsInterface ) : Observable < string | void > {
2522 return ( new RemoteScreenCapture ) . getDriver ( ) . pipe (
2623 concatMap ( ( driver : ThenableWebDriver ) => {
27- return from ( driver . get ( URI ) ) . pipe (
24+ return from ( driver . manage ( ) . window ( ) . setRect ( {
25+ width : options && options . width ? options . width : 2880 ,
26+ height : options && options . height ? options . height : 1800
27+ } ) ) . pipe (
28+ concatMap ( ( ) => from ( driver . get ( URI ) ) ) ,
2829 concatMap ( ( ) => from ( driver . takeScreenshot ( ) ) ) ,
2930 tap ( ( ) => from ( driver . close ( ) ) )
3031 )
3132 } ) ,
3233 map ( ( encodedPngChunks ) => {
33- if ( savePath ) {
34- const absoluteSavePath = `${ savePath } /${ new Date ( ) . getTime ( ) } .png` ;
34+ if ( options && options . savePath ) {
35+ const absoluteSavePath = `${ options . savePath } /${ new Date ( ) . getTime ( ) } .png` ;
3536 fs . writeFileSync ( absoluteSavePath , encodedPngChunks , 'base64' ) ;
3637 return absoluteSavePath ;
3738 }
0 commit comments