
Another wandering soul screaming into the void. If you are looking for my blog you are in the wrong place. The profile and header pictures are brought to you by @cdd20.
My puppeteer scripts now use deno.
No more need for npm in my personal stack! spawnSync
+
which
returns the local browser’s path.
import puppeteer from "https://deno.land/x/puppeteer@16.2.0/mod.ts";
const chrome = "firefox"; /* Browser Chrome: "firefox" | "chromium" | "google-chrome" | ... */
const product = "firefox"; /* Product Base: "firefox" | "chrome" */
const { status, stdout, stderr } = Deno.spawnSync("which", {
args: [ chrome, ],
});
const executablePath = new TextDecoder().decode(stdout).trim();
const browser = await puppeteer.launch({
headless: false,
executablePath: executablePath,
product: product,
});
const page = await browser.newPage();
await page.setViewport({ width: 1024, height: 768, });
const sites = [ "example.com", ];
for (const site of sites) {
await page.goto("http://" + site);
await page.screenshot({ path: site + ".png" });
}
await browser.close();
deno run --allow-all --unstable main.ts