Puppeteer press enter on print dialog screen has no effect

放肆的年华 提交于 2021-01-29 20:50:56

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!