+++ date = "2022-08-26T22:20:38+00:00" lastmod = "2022-08-28T01:37:55+00:00" tags = [ "webdev", "gists" ] author = "tdro" +++ {{< disclose "My [puppeteer](https://pptr.dev/) scripts now use [deno](https://deno.land/)." />}} No more need for [npm](https://www.npmjs.com/) in my personal stack! The native browser's path comes from `which`. ```javascript {options="hl_lines=3-4 6-8",caption="Basic Boilerplate: Captures a picture of [example.com](https://example.com) (main.ts)"} import puppeteer from "https://deno.land/x/puppeteer@16.2.0/mod.ts"; const chrome = "chromium"; // Browser Chrome: "firefox" | "chromium" | "google-chrome" | ... const product = "chrome"; // Product Base: "firefox" | "chrome" const command = new Deno.Command("which", { args: [chrome] }); const { status, stdout, stderr } = command.outputSync(); const executablePath = new TextDecoder().decode(stdout).trim(); const browser = await puppeteer.launch({ headless: false, executablePath: executablePath, product: product, }); const site = "example.com"; const page = await browser.newPage(); await page.setViewport({ width: 1024, height: 768 }); await page.goto("https://" + site); await page.screenshot({ path: site + ".png" }); await page.waitForSelector('a'); const url = await page.evaluate(() => { return document.querySelector('a').href; }); console.log(url); await browser.close(); ``` ```shell {caption="Deno Version: 1.45.5"} deno run --allow-all main.ts ```