Mat*_*itt 12 javascript node.js puppeteer
尝试使用 Puppetter 打印 PDF 时出现以下错误。我在网上找不到有关此错误的更多信息。这是否意味着该特定页面不支持 PDF,或者我的代码中是否有可以修改此设置的设置?任何帮助,将不胜感激。
export const create = async (dev: boolean = true) => {
const username = process.env.USERNAME;
const password = process.env.PASSWORD;
const options = dev
? {
headless: false,
slowMo: 25,
}
: {};
const browser = await Puppeteer.launch(options);
const page = await browser.newPage();
await page.goto(LOGIN_URL, {
waitUntil: "networkidle2",
});
await page.type(USERNAME_INPUT_ID, username);
const passwordInputHandle = await page.$(PASSWORD_INPUT_ID);
await passwordInputHandle.type(password);
await passwordInputHandle.press("Enter");
await page.pdf({ path: path.join(TEMP_FOLDER, "hn.pdf"), format: "a4" });
await browser.close();
};
Run Code Online (Sandbox Code Playgroud)
Sil*_*egy 24
仅在 模式下支持PDF 创建headless。
所以这应该有效:
const browser = await Puppeteer.launch({ headless: true });
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10170 次 |
| 最近记录: |