Skip to content

Commit e0d4b54

Browse files
authored
Create chromium.ts
1 parent dc743b6 commit e0d4b54

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

api/_lib/chromium.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { launch, Page } from 'puppeteer-core';
2+
import { getOptions } from './options';
3+
let _page: Page | null;
4+
5+
async function getPage() {
6+
if (_page) {
7+
return _page;
8+
}
9+
const options = await getOptions(false);
10+
const browser = await launch(options);
11+
_page = await browser.newPage();
12+
return _page;
13+
}
14+
15+
export async function getScreenshot(url, width, height) {
16+
const page = await getPage();
17+
await page.goto(url);
18+
await page.setViewport({ width: width || 1920, height: height || 1080 });
19+
const file = await page.screenshot({ 'png' });
20+
return file;
21+
}

0 commit comments

Comments
 (0)