-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
chromium.ts
59 lines (51 loc) · 1.64 KB
/
chromium.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { launch, Browser } from "puppeteer-core";
import chromeAws from "chrome-aws-lambda";
export async function createBrowser(args: ChromeLaunchOptions = {}): Promise<Browser> {
const defaults: ChromeLaunchOptions = {
defaultViewport: {
deviceScaleFactor: 1,
width: 1280,
height: 640,
},
ignoreHTTPSErrors: true,
};
let options: ChromeLaunchOptions = {};
if (isDev()) {
options = {
...defaults,
...args,
...{
args: [],
executablePath: lookupChrome(),
headless: true,
}
};
} else {
options = {
...defaults,
...args,
...{
args: chromeAws.args,
executablePath: await chromeAws.executablePath,
headless: chromeAws.headless,
}
};
}
// Extra fonts
await chromeAws.font('https://rawcdn.githack.com/rsms/inter/378ab05866aab4cb0d71a5f502961d6a54da0770/docs/font-files/Inter-Regular.woff2');
await chromeAws.font('https://rawcdn.githack.com/rsms/inter/378ab05866aab4cb0d71a5f502961d6a54da0770/docs/font-files/Inter-SemiBold.woff2');
await chromeAws.font('https://rawcdn.githack.com/rsms/inter/378ab05866aab4cb0d71a5f502961d6a54da0770/docs/font-files/Inter-Bold.woff2');
return await launch(options);
}
function lookupChrome(): string {
if (process.platform === 'win32') {
return 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe';
}
if (process.platform === 'darwin') {
return '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
}
return 'google-chrome';
}
function isDev(): boolean {
return process.env.NOW_REGION === undefined || process.env.NOW_REGION === 'dev1';
}