Puppeteer 在打印对话框屏幕上按 Enter 键无效 [英] Puppeteer press enter on print dialog screen has no effect

查看:80
本文介绍了Puppeteer 在打印对话框屏幕上按 Enter 键无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 puppeteer 脚本,它循环遍历要打印为 pdf 的页面列表(不是通过 puppeteer page.pdf),但带有打印预览对话框.当它到达这里时,我已经更改了页面的标题,以便相应地命名文件.当无头模式为 false 时,我看到它停在打印预览对话框中,我可以在其中按 Enter,然后再次输入以获取保存页面的位置,这很好.所以在代码中我使用 'await page.keyboard.press('Enter');'两次,但它们不起作用.输入代码在登录屏幕上工作正常.打印预览对话框没有得到输入事件有什么我遗漏的吗?我需要用铬设置任何特定的标志吗?是否有某种解决方法?

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?

推荐答案

Puppeteer's

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);

而且效果很好

这篇关于Puppeteer 在打印对话框屏幕上按 Enter 键无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆