Skip to content

Commit d5cd41f

Browse files
committed
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

0 commit comments

Comments
 (0)