问题
I have a puppeteer script that loops through a list of pages to print as pdfs (not via puppeteer page.pdf) but with the print preview dialog. when it reaches here i have changed the title of the page so that the file will be named accordingly. When headless mode is false I see it stop at the print preview dialog in which i can just press enter, and enter again for the location to save the page and thats fine. So in code I use 'await page.keyboard.press('Enter');' twice but they don't work. The code for enter works fine on the login screen. Is there anything Im missing for the print preview dialog not getting the enter event? Do i need to set any specific flags with chromium? Is there a workaround of some sort?
回答1:
Puppeteer's
await page.keyboard.press('Enter');
wouldn't work for me so i used
const { keyboard, Key } = require("@nut-tree/nut-js");
keyboard.config.autoDelayMs = 0;
await keyboard.pressKey(Key.Enter);
and it worked perfectly
来源:https://stackoverflow.com/questions/64401867/puppeteer-press-enter-on-print-dialog-screen-has-no-effect