Skip to content

Commit 50e7400

Browse files
authored
chore(export): upgrade puppeteer and chromium for Node 18 support (#3501)
1 parent 51a0202 commit 50e7400

File tree

6 files changed

+98
-116
lines changed

6 files changed

+98
-116
lines changed

export/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
},
1919
"dependencies": {
2020
"@sentry/node": "5.30.0",
21+
"@sparticuz/chromium": "92.0.0",
2122
"axios": "0.21.2",
2223
"bunyan": "1.8.15",
23-
"chrome-aws-lambda": "~6.0.0",
2424
"fs-extra": "9.1.0",
2525
"http-graceful-shutdown": "2.3.2",
2626
"koa": "2.13.1",
@@ -29,7 +29,7 @@
2929
"lodash": "4.17.21",
3030
"nodemon": "2.0.22",
3131
"pug": "3.0.2",
32-
"puppeteer-core": "5.5.0"
32+
"puppeteer-core": "10.4.0"
3333
},
3434
"devDependencies": {
3535
"@types/fs-extra": "9.0.13",
@@ -39,13 +39,11 @@
3939
"@types/lodash": "4.14.196",
4040
"@types/node": "18.17.3",
4141
"@types/pug": "2.0.6",
42-
"@types/puppeteer": "^5.4.7",
4342
"@vercel/node": "1.15.4",
4443
"cross-env": "7.0.3",
4544
"dotenv": "8.2.0",
4645
"npm-run-all": "4.1.5",
4746
"prettier": "2.8.8",
48-
"puppeteer": "~6.0.0",
4947
"typescript": "5.1.6"
5048
}
5149
}

export/src/handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as Sentry from '@sentry/node';
22
import type { NowApiHandler, NowRequest, NowResponse } from '@vercel/node';
3-
import type { Page } from 'puppeteer';
3+
import type { Page } from 'puppeteer-core';
44

55
import * as render from './render-serverless';
66
import config from './config';

export/src/render-serverless.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import chromium from 'chrome-aws-lambda';
2-
import type { Page } from 'puppeteer';
1+
import chromium from '@sparticuz/chromium';
2+
import puppeteer, { Page } from 'puppeteer-core';
33

44
import { getModules } from './data';
55
import config from './config';
@@ -23,7 +23,7 @@ async function setViewport(page: Page, options: ViewportOptions = {}) {
2323
}
2424

2525
export async function open(url: string) {
26-
const browser = await chromium.puppeteer.launch({
26+
const browser = await puppeteer.launch({
2727
// devtools: !!process.env.DEVTOOLS, // TODO: Query string && NODE_ENV === 'development'?
2828
args: chromium.args,
2929
defaultViewport: chromium.defaultViewport,
@@ -72,7 +72,7 @@ export async function pdf(page: Page, data: PageData) {
7272

7373
return await page.pdf({
7474
printBackground: true,
75-
format: 'A4',
75+
format: 'a4',
7676
landscape: data.theme.timetableOrientation === 'HORIZONTAL',
7777
});
7878
}

export/src/render.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fs from 'fs-extra';
2-
import puppeteer, { Page } from 'puppeteer';
2+
import puppeteer, { Page } from 'puppeteer-core';
33
import type { Middleware } from 'koa';
44

55
import { getModules } from './data';
@@ -106,7 +106,7 @@ export async function pdf(page: Page, data: PageData) {
106106

107107
return await page.pdf({
108108
printBackground: true,
109-
format: 'A4',
109+
format: 'a4',
110110
landscape: data.theme.timetableOrientation === 'HORIZONTAL',
111111
});
112112
}

export/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Page } from 'puppeteer';
1+
import type { Page } from 'puppeteer-core';
22

33
export type TimetableOrientation = 'HORIZONTAL' | 'VERTICAL';
44

0 commit comments

Comments
 (0)