Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d5cd41f

Browse files
committedJun 16, 2025··
Refactor PDF generation to use Playwright Chromium instead of Puppeteer
- Updated dependencies in package.json and package-lock.json to include playwright-chromium. - Modified markdown-to-pdf.js to replace Puppeteer with Playwright for PDF generation, enhancing performance and compatibility. - Adjusted launch options and page settings for Playwright. Co-authored-by: Yukaii <[email protected]>
1 parent 1822ed5 commit d5cd41f

File tree

3 files changed

+101
-1702
lines changed

3 files changed

+101
-1702
lines changed
 

‎lib/utils/markdown-to-pdf.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const puppeteer = require('puppeteer')
3+
const { chromium } = require('playwright-chromium')
44
const markdownit = require('markdown-it')
55
const path = require('path')
66
const fs = require('fs')
@@ -131,13 +131,12 @@ async function convertMarkdownToPDF (markdown, outputPath, options = {}) {
131131
</body>
132132
</html>`
133133

134-
// Launch puppeteer and generate PDF
134+
// Launch Playwright Chromium and generate PDF
135135
let browser = null
136136
try {
137-
browser = await puppeteer.launch({
138-
headless: 'new',
139-
args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage'],
140-
timeout: 30000 // 30 second timeout
137+
browser = await chromium.launch({
138+
headless: true,
139+
args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage']
141140
})
142141

143142
const page = await browser.newPage()
@@ -146,8 +145,7 @@ async function convertMarkdownToPDF (markdown, outputPath, options = {}) {
146145
page.setDefaultTimeout(30000)
147146

148147
await page.setContent(fullHtml, {
149-
waitUntil: 'networkidle0',
150-
timeout: 30000
148+
waitUntil: 'networkidle'
151149
})
152150

153151
await page.pdf({
@@ -159,8 +157,7 @@ async function convertMarkdownToPDF (markdown, outputPath, options = {}) {
159157
bottom: '20px',
160158
left: '20px'
161159
},
162-
printBackground: true,
163-
timeout: 30000
160+
printBackground: true
164161
})
165162

166163
return true

‎package-lock.json

Lines changed: 93 additions & 1691 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@
8787
"passport.socketio": "~3.7.0",
8888
"pg": "~8.8.0",
8989
"pg-hstore": "~2.3.2",
90+
"playwright-chromium": "^1.53.0",
9091
"prom-client": "^11.0.0",
9192
"prometheus-api-metrics": "^2.2.5",
92-
"puppeteer": "^21.11.0",
9393
"randomcolor": "~0.5.4",
9494
"read-chunk": "^3.2.0",
9595
"readline-sync": "~1.4.7",

0 commit comments

Comments
 (0)
Please sign in to comment.