Deno Puppeteer

A port of puppeteer running on Deno
Alternatives To Deno Puppeteer
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Puppeteer82,48412,12810,93211 hours ago761September 22, 2022260apache-2.0TypeScript
Headless Chrome Node.js API
Qawolf3,209212a month ago30February 24, 2020otherTypeScript
🐺 Create browser tests 10x faster
Puppeteer Examples2,377
3 years ago14apache-2.0JavaScript
Puppeteer example scripts for running Headless Chrome from Node.
Reactopt1,970
45 years ago24December 07, 20179JavaScript
A CLI React performance optimization tool that identifies potential unnecessary re-rendering
Awesome Regression Testing1,794
5 months ago3cc-by-sa-4.0
🕶️ A curated list of resources around the topic: visual regression testing
Ui Testing Best Practices1,468
11 hours ago3cc-by-sa-4.0
The largest UI testing best practices list (last update: March 2023)
Puphpeteer1,31915123 months ago13December 01, 202064mitPHP
A Puppeteer bridge for PHP, supporting the entire API.
Awesome Jest1,297
a month ago1mit
🕶Awesome Jest packages and resources
Karmatic1,178346310 months ago16May 23, 202210JavaScript
🦑 Easy automatic (headless) browser testing with Jest's API, but powered by Karma & Webpack.
Spearmint1,142
2 months ago7mitJavaScript
Testing, simplified. || An inclusive, accessibility-first GUI for generating clean, semantic Javascript tests in only a few clicks of a button.
Alternatives To Deno Puppeteer
Select To Compare


Alternative Project Comparisons
Readme

deno-puppeteer

API

A fork of Puppeteer running on Deno.

Puppeteer is a library which provides a high-level API to control Chrome, Chromium, or Firefox Nightly over the DevTools Protocol. Puppeteer runs headless by default, but can be configured to run full (non-headless) Chrome or Chromium.

Most things that you can do manually in the browser can be done using Puppeteer! Here are a few examples to get you started:

  • Generate screenshots and PDFs of pages.
  • Crawl a SPA (Single-Page Application) and generate pre-rendered content (i.e. "SSR" (Server-Side Rendering)).
  • Automate form submission, UI testing, keyboard input, etc.
  • Create an up-to-date, automated testing environment. Run your tests directly in the latest version of Chrome using the latest JavaScript and browser features.
  • Capture a timeline trace of your site to help diagnose performance issues.
  • Test Chrome Extensions.

Getting Started

Installation

To use Puppeteer, import it like so:

import puppeteer from "https://deno.land/x/[email protected]/mod.ts";

Puppeteer can use any recent version of Chromium or Firefox Nightly, but this version of Puppeteer is only validated against a specific version. To cache these versions in the Puppeteer cache, run the commands below.

PUPPETEER_PRODUCT=chrome deno run -A --unstable https://deno.land/x/[email protected]/install.ts
PUPPETEER_PRODUCT=firefox deno run -A --unstable https://deno.land/x/[email protected]/install.ts

You can find all of the supported environment variables to customize installation in the Puppeteer docs.

Usage

Puppeteer will be familiar to people using other browser testing frameworks. You create an instance of Browser, open pages, and then manipulate them with Puppeteer's API.

Example - navigating to https://example.com and saving a screenshot as example.png:

Save file as example.js

import puppeteer from "https://deno.land/x/[email protected]/mod.ts";

const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto("https://example.com");
await page.screenshot({ path: "example.png" });

await browser.close();

Execute script on the command line

deno run -A --unstable example.js

Puppeteer sets an initial page size to 800600px, which defines the screenshot size. The page size can be customized with Page.setViewport().

Example - create a PDF.

Save file as hn.js

import puppeteer from "https://deno.land/x/[email protected]/mod.ts";

const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto("https://news.ycombinator.com", {
  waitUntil: "networkidle2",
});
await page.pdf({ path: "hn.pdf", format: "A4" });

await browser.close();

Execute script on the command line

deno run -A --unstable hn.js

See Page.pdf() for more information about creating pdfs.

Example - evaluate script in the context of the page

Save file as get-dimensions.js

import puppeteer from "https://deno.land/x/[email protected]/mod.ts";

const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto("https://example.com");

// Get the "viewport" of the page, as reported by the page.
const dimensions = await page.evaluate(() => {
  return {
    width: document.documentElement.clientWidth,
    height: document.documentElement.clientHeight,
    deviceScaleFactor: window.devicePixelRatio,
  };
});

console.log("Dimensions:", dimensions);

await browser.close();

Execute script on the command line

deno run -A --unstable get-dimensions.js

FAQ

How does deno-puppeteer compare to the Node version?

deno-puppeteer effectively runs a regular version of Puppeteer, except for some minor changes to make it compatible with Deno.

The most noticable difference is likely that instead of some methods taking / returning Node Buffer, they take / return Uint8Array. One method also returns a web native ReadableStream instead of the Node Readable.

Other than this, the documentation on https://pptr.dev generally applies.

How to run in Docker?

An example Dockerfile can be found in this repository. It will install all necessary dependencies, and shows how to run the ./examples/docker.js.

It is just meant as a jumping off point - customize it as you wish.

Popular Puppeteer Projects
Popular Testing Projects
Popular Web Browsers Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Typescript
Testing
Screenshot
Puppeteer
Headless Chrome