admin管理员组文章数量:1201410
I get the below error when trying to print PDF with Puppetter. I've not been able to find much information about this error online. Does this mean this particular page just doesn't support PDF or is there a setting in my code that could ammend this? Any help would be appreciated.
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();
};
I get the below error when trying to print PDF with Puppetter. I've not been able to find much information about this error online. Does this mean this particular page just doesn't support PDF or is there a setting in my code that could ammend this? Any help would be appreciated.
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();
};
Share
Improve this question
asked Jan 30, 2022 at 22:51
Matt HerbstrittMatt Herbstritt
4,8625 gold badges28 silver badges32 bronze badges
1 Answer
Reset to default 25PDF creation is only supported in headless
mode.
So this should work:
const browser = await Puppeteer.launch({ headless: true });
版权声明:本文标题:javascript - Puppeteer - ProtocolError: Protocol error (Page.printToPDF): Printing is not available - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738585988a2101431.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论