I’m working on a web automation project where I need to click a print button that triggers a server request and displays a print dialog window. The challenge is that this content doesn’t come from a direct URL, so I can’t just navigate to it and use the standard PDF generation methods.
When I click the print button, it shows a browser print dialog with the document I need to save. I’m wondering if there’s a way to capture this dialog content and convert it to PDF using Puppeteer.
Here’s my current automation script:
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const pageInstance = await browser.newPage();
await pageInstance.setViewport({width: 1366, height: 1800});
await pageInstance.goto(`https://www.southwest.com/air/check-in/review.html?confirmationNumber=${process.argv[2]}&passengerFirstName=${process.argv[3]}&passengerLastName=${process.argv[4]}`, {
waitUntil: 'networkidle2'
});
const [confirmCode, buttonLabel] = [await pageInstance.$eval('.confirmation-number--code', element => element.innerHTML), await pageInstance.$eval('.actionable_primary.actionable_large-button', element => element.innerHTML)];
console.log(buttonLabel);
console.log(confirmCode);
await pageInstance.click('.actionable_primary.actionable_large-button');
await pageInstance.click('.air-check-in-boarding-pass-options .boarding-pass-options--button-email, .air-check-in-boarding-pass-options .boarding-pass-options--button-print, .air-check-in-boarding-pass-options .boarding-pass-options--button-text');
await browser.close();
})();
Any suggestions on how to handle the print dialog and save the content as PDF would be really helpful.