Back to packages list

Vals using puppeteer-core

Description from the NPM package:
A high-level API to control headless Chrome over the DevTools Protocol

Some kind of readme

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { email as sendEmail } from "https://esm.town/v/std/email?v=9";
import puppeteer from "npm:puppeteer-core";
/**
* This requires a free API token from browserless.io saved in your
* Env Variables as BROWSERLESS_API_KEY
*/
let sendPDF = async (subject, html) => {
const browserlessApi = Deno.env.get("BROWSERLESS_API_KEY");
const browser = await puppeteer.connect({
browserWSEndpoint: `wss://chrome.browserless.io?token=${browserlessApi}`,
});
const page = await browser.newPage();
await page.setContent(html);
const screenshot = await page.pdf();
await page.close();
await browser.close();
return sendEmail({
subject: "PDFified: " + subject,
// html: html,
attachments: [{
content: screenshot.toString("base64"),
filename: (subject || "Untitled") + ".pdf",
type: "application/pdf",
disposition: "attachment",
}],
});
};
export default async function(email: Email) {
console.log(email);
await sendPDF(email.subject, email.html);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import puppeteer from "npm:puppeteer-core";
export default async () => {
const browserlessApi = Deno.env.get("BROWSERLESS_API_KEY");
const browser = await puppeteer.connect({
browserWSEndpoint: `wss://chrome.browserless.io?token=${browserlessApi}`,
});
const page = await browser.newPage();
const html = "<h1>hi</h1>";
await page.setContent(html);
const screenshot = await page.pdf();
await page.close();
await browser.close();
return new Response(screenshot, {
headers: {
"Content-Type": "application/pdf",
},
});
};
1
Next