XWX-AI commited on
Commit
ea21983
·
1 Parent(s): 89c8cea

Fix: Replace deprecated page.waitForTimeout with delay helper

Browse files

- page.waitForTimeout() was removed in Puppeteer v19+
- Use custom delay() function with setTimeout instead
- Fixes 500 error when generating PDFs

Files changed (1) hide show
  1. server.js +5 -2
server.js CHANGED
@@ -6,6 +6,9 @@ const cors = require('cors');
6
  const app = express();
7
  const port = 7860;
8
 
 
 
 
9
  // Enable CORS for all origins (or restrict to gemini.google.com)
10
  app.use(cors());
11
 
@@ -66,7 +69,7 @@ app.post('/api/generate_pdf', async (req, res) => {
66
 
67
  // Wait for images to fully render (additional 3 seconds for base64 decoding)
68
  console.log('[PDF-GEN] Waiting for images to render...');
69
- await page.waitForTimeout(3000);
70
  console.log('[PDF-GEN] Image render wait complete');
71
 
72
  // Count images in the rendered page
@@ -97,7 +100,7 @@ app.post('/api/generate_pdf', async (req, res) => {
97
  console.log('[PDF-GEN] Scroll complete');
98
 
99
  // Wait additional time for any lazy-loaded images
100
- await page.waitForTimeout(2000);
101
 
102
  // Inject styles to ensure 100% width and print media simulation
103
  await page.addStyleTag({
 
6
  const app = express();
7
  const port = 7860;
8
 
9
+ // Helper function for delay (replacement for deprecated page.waitForTimeout)
10
+ const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
11
+
12
  // Enable CORS for all origins (or restrict to gemini.google.com)
13
  app.use(cors());
14
 
 
69
 
70
  // Wait for images to fully render (additional 3 seconds for base64 decoding)
71
  console.log('[PDF-GEN] Waiting for images to render...');
72
+ await delay(3000);
73
  console.log('[PDF-GEN] Image render wait complete');
74
 
75
  // Count images in the rendered page
 
100
  console.log('[PDF-GEN] Scroll complete');
101
 
102
  // Wait additional time for any lazy-loaded images
103
+ await delay(2000);
104
 
105
  // Inject styles to ensure 100% width and print media simulation
106
  await page.addStyleTag({