Skip to content
This repository has been archived by the owner on Jan 21, 2023. It is now read-only.

Make it super fast #31

Merged
merged 1 commit into from
Jan 28, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/chromium.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import * as chromeAwsLambda from 'chrome-aws-lambda';
import { launch } from 'puppeteer-core';
const chrome = chromeAwsLambda as any;
import * as chromeAws from 'chrome-aws-lambda';
import { launch, Page } from 'puppeteer-core';
let _page: Page | null;

export async function getScreenshot(url: string, type: FileType) {
async function getPage() {
if (_page) {
return _page;
}
const chrome = chromeAws as any;
const browser = await launch({
args: chrome.args,
executablePath: await chrome.executablePath,
headless: chrome.headless,
});
_page = await browser.newPage();
return _page;
}

const page = await browser.newPage();
export async function getScreenshot(url: string, type: FileType) {
const page = await getPage();
await page.setViewport({ width: 2048, height: 1170 });
await page.goto(url);
const file = await page.screenshot({ type });
await browser.close();
return file;
}