mirror of
https://github.com/FlipsideCrypto/og-image.git
synced 2026-02-06 10:46:43 +00:00
- Upgrade Node 10 to Node 12 - Bump dependencies to the latest version - Fix a small typescript issue @Snazzyham mentioned #105 - Fix perf by using `setContent()` instead of writing a file each request per @ChristopherBiscardi, [suggested on twitter](https://twitter.com/chrisbiscardi/status/1239686555972718593)
23 lines
664 B
TypeScript
23 lines
664 B
TypeScript
import { launch, Page } from 'puppeteer-core';
|
|
import { getOptions } from './options';
|
|
import { FileType } from './types';
|
|
let _page: Page | null;
|
|
|
|
async function getPage(isDev: boolean) {
|
|
if (_page) {
|
|
return _page;
|
|
}
|
|
const options = await getOptions(isDev);
|
|
const browser = await launch(options);
|
|
_page = await browser.newPage();
|
|
return _page;
|
|
}
|
|
|
|
export async function getScreenshot(html: string, type: FileType, isDev: boolean) {
|
|
const page = await getPage(isDev);
|
|
await page.setViewport({ width: 2048, height: 1170 });
|
|
await page.setContent(html);
|
|
const file = await page.screenshot({ type });
|
|
return file;
|
|
}
|