Skip to content

Commit 0a7303d

Browse files
committed
Add options and update docs
1 parent ae5c5c2 commit 0a7303d

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

src/.DS_Store

6 KB
Binary file not shown.

src/interface/options.interface.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export interface OptionsInterface {
2+
readonly width?: number;
3+
readonly height?: number;
4+
readonly savePath?: string;
5+
}

src/remote-screen-capture.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,35 @@ import * as chromeDriver from 'chromedriver';
44
import {ThenableWebDriver, Builder, Capabilities} from 'selenium-webdriver';
55
import {from, of, Observable} from 'rxjs';
66
import {concatMap, map, tap} from 'rxjs/operators';
7+
import {OptionsInterface} from './interface/options.interface';
78

89
export 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

Comments
 (0)