Spaces:
Running
Running
Upgrade Puppeteer to v24.x for better PDF generation
Browse files- Upgrade puppeteer from 22.0.0 to 24.x (latest)
- Update browser launch configuration for Puppeteer 24.x compatibility
- Add auto-detection for system Chrome vs bundled Chrome
- Update documentation with changelog
- README.md +11 -2
- package.json +2 -2
- server.js +23 -5
README.md
CHANGED
|
@@ -13,8 +13,17 @@ short_description: Backend server for AI Chat Exporter and personal web tools.
|
|
| 13 |
# Universal Backend Service for Chrome Extensions
|
| 14 |
|
| 15 |
This generic backend service provides:
|
| 16 |
-
- **PDF Generation**: High-fidelity HTML-to-PDF conversion using
|
| 17 |
-
- **Extensible**: Ready to add more
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
## Deployment
|
| 20 |
Deployed via Docker on Hugging Face Spaces.
|
|
|
|
| 13 |
# Universal Backend Service for Chrome Extensions
|
| 14 |
|
| 15 |
This generic backend service provides:
|
| 16 |
+
- **PDF Generation**: High-fidelity HTML-to-PDF conversion using Puppeteer (Chrome-based).
|
| 17 |
+
- **Extensible**: Ready to add more utilities.
|
| 18 |
+
|
| 19 |
+
## Changelog
|
| 20 |
+
|
| 21 |
+
### v1.1.0 (2026-02-12)
|
| 22 |
+
- **Upgraded Puppeteer**: 22.0.0 → 24.x (Latest)
|
| 23 |
+
- Chrome for Testing integration
|
| 24 |
+
- Better headless mode support
|
| 25 |
+
- Potential PDF image compression improvements
|
| 26 |
+
- **Improved browser detection**: Auto-detect system Chrome or use bundled version
|
| 27 |
|
| 28 |
## Deployment
|
| 29 |
Deployed via Docker on Hugging Face Spaces.
|
package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
| 1 |
|
| 2 |
{
|
| 3 |
"name": "pdf-server",
|
| 4 |
-
"version": "1.
|
| 5 |
"description": "Puppeteer PDF Generator for Hugging Face Spaces",
|
| 6 |
"main": "server.js",
|
| 7 |
"dependencies": {
|
| 8 |
"express": "^4.18.2",
|
| 9 |
-
"puppeteer": "^
|
| 10 |
"cors": "^2.8.5"
|
| 11 |
},
|
| 12 |
"scripts": {
|
|
|
|
| 1 |
|
| 2 |
{
|
| 3 |
"name": "pdf-server",
|
| 4 |
+
"version": "1.1.0",
|
| 5 |
"description": "Puppeteer PDF Generator for Hugging Face Spaces",
|
| 6 |
"main": "server.js",
|
| 7 |
"dependencies": {
|
| 8 |
"express": "^4.18.2",
|
| 9 |
+
"puppeteer": "^24.0.0",
|
| 10 |
"cors": "^2.8.5"
|
| 11 |
},
|
| 12 |
"scripts": {
|
server.js
CHANGED
|
@@ -48,9 +48,9 @@ app.post('/api/generate_pdf', async (req, res) => {
|
|
| 48 |
console.log(`[PDF-GEN] Calculated wait times: base=${baseWaitTime}ms, size=${sizeWaitTime}ms, total=${totalWaitTime}ms`);
|
| 49 |
|
| 50 |
// Launch Chrome
|
| 51 |
-
//
|
| 52 |
-
|
| 53 |
-
|
| 54 |
args: [
|
| 55 |
'--no-sandbox',
|
| 56 |
'--disable-setuid-sandbox',
|
|
@@ -60,8 +60,26 @@ app.post('/api/generate_pdf', async (req, res) => {
|
|
| 60 |
'--disable-software-rasterizer',
|
| 61 |
'--memory-pressure-off'
|
| 62 |
],
|
| 63 |
-
headless:
|
| 64 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
const page = await browser.newPage();
|
| 67 |
|
|
|
|
| 48 |
console.log(`[PDF-GEN] Calculated wait times: base=${baseWaitTime}ms, size=${sizeWaitTime}ms, total=${totalWaitTime}ms`);
|
| 49 |
|
| 50 |
// Launch Chrome
|
| 51 |
+
// Puppeteer 24.x uses Chrome for Testing by default
|
| 52 |
+
// If chromium is installed via apt-get, use it; otherwise Puppeteer will download Chrome
|
| 53 |
+
const launchOptions = {
|
| 54 |
args: [
|
| 55 |
'--no-sandbox',
|
| 56 |
'--disable-setuid-sandbox',
|
|
|
|
| 60 |
'--disable-software-rasterizer',
|
| 61 |
'--memory-pressure-off'
|
| 62 |
],
|
| 63 |
+
headless: true
|
| 64 |
+
};
|
| 65 |
+
|
| 66 |
+
// Try to use system chromium if available, otherwise use bundled Chrome
|
| 67 |
+
try {
|
| 68 |
+
const fs = require('fs');
|
| 69 |
+
if (fs.existsSync('/usr/bin/chromium')) {
|
| 70 |
+
launchOptions.executablePath = '/usr/bin/chromium';
|
| 71 |
+
console.log('[PDF-GEN] Using system Chromium');
|
| 72 |
+
} else if (fs.existsSync('/usr/bin/google-chrome')) {
|
| 73 |
+
launchOptions.executablePath = '/usr/bin/google-chrome';
|
| 74 |
+
console.log('[PDF-GEN] Using system Google Chrome');
|
| 75 |
+
} else {
|
| 76 |
+
console.log('[PDF-GEN] Using bundled Chrome for Testing');
|
| 77 |
+
}
|
| 78 |
+
} catch (e) {
|
| 79 |
+
console.log('[PDF-GEN] Using bundled Chrome for Testing');
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
browser = await puppeteer.launch(launchOptions);
|
| 83 |
|
| 84 |
const page = await browser.newPage();
|
| 85 |
|