• Stars
    star
    445
  • Rank 98,085 (Top 2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 4 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A port of puppeteer running on Deno

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 800×600px, 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.

More Repositories

1

now-deno

Deno builder for Vercel - run Deno on Vercel. 🦕 + λ = ❤️
TypeScript
264
star
2

dext.ts

The Preact Framework for Deno
TypeScript
241
star
3

esbuild_deno_loader

Deno module resolution for `esbuild`
TypeScript
171
star
4

armadajs

A custom JavaScript runtime for the ArmadaJS conference
Rust
87
star
5

fresh-with-signals

Using @preact/signals in Fresh
TypeScript
82
star
6

deno_s3

Amazon S3 for Deno
TypeScript
54
star
7

deploy_chat

A live chat app running on Deno Deploy
TypeScript
40
star
8

proposal-binary-encoding

A proposal to add modern, easy to use binary encoders to the web platform.
JavaScript
40
star
9

deno_httpcache

HTTP Caching for Deno - in memory and redis storage support. Inspired by the Service Worker Cache API.
TypeScript
25
star
10

freshworkshop

TypeScript
21
star
11

workerkit

A library to make writing Cloudflare Workers way nicer
TypeScript
21
star
12

ammonia-wasm

WASM bindings for the Ammonia HTML sanitizer
TypeScript
20
star
13

wrap

wrap is an abstraction layer on top of mongodb 🍃 to make it feel like sorta like firestore 🔥
Go
19
star
14

deno_googleapis

TypeScript
19
star
15

comrak-wasm

WASM bindings for the comrak markdown renderer
TypeScript
17
star
16

mqtt

A nice MQTT client library that wraps paho.mqtt.golang
Go
17
star
17

puppeteer_on_deploy

Running puppeteer on Deno Deploy!
TypeScript
16
star
18

deno_local_file_fetch

This polyfills file:// support for `fetch`
TypeScript
12
star
19

deno-fetchevent

FetchEvent based server compatible with browser.
TypeScript
11
star
20

deno_aws_sign_v4

Generate AWS Signature V4 for AWS low-level REST APIs.
TypeScript
10
star
21

messageformat.dev

TypeScript
10
star
22

denopaste

TypeScript
9
star
23

fetchevent_examples

Examples that make use of web standard FetchEvent
JavaScript
9
star
24

floatplaneapi

An unofficial API to interface with floatplane.com from own systems. This is not in any way affiliated with floatplane.com.
TypeScript
8
star
25

cases

TypeScript
7
star
26

rethinkdb-deno

A RethinkDB driver for deno.
TypeScript
6
star
27

deno_sqs

Amazon SQS for Deno
TypeScript
6
star
28

proposal-semaphore

6
star
29

deno_xhr

XMLHttpRequest polyfill for Deno
6
star
30

x.lcas.dev

A CDN that serves X-TypeScript-Types headers.
JavaScript
6
star
31

deno_ssm

Amazon SSM sdk from Deno
TypeScript
5
star
32

rethinkdb-kubernetes

RethinkDB on Kubernetes
Shell
4
star
33

flag

TypeScript
4
star
34

stream-utils

TypeScript
4
star
35

antictf

A CTF platform that uses Google Cloud for infinite scalability.
TypeScript
4
star
36

runtime-detector

TypeScript
4
star
37

greeter

TypeScript
3
star
38

branch-protection-test

3
star
39

lspower

Rust library for the Language Server Protocol (LSP)
Rust
3
star
40

luca

TypeScript
3
star
41

deno_doc_discord

A discord integration for deno doc
TypeScript
3
star
42

deno_metrics

Runtime metrics for Deno
TypeScript
3
star
43

wgpu_cts_runner

A minimal JS runtime built on Deno (deno_core / extensions) that can be used to test WebGPU CTS outside of full Deno.
Rust
3
star
44

reqwest_connection_pooling_bug

Reproduction for reqwest connection pooling bug
Rust
3
star
45

base64_streams

TypeScript
2
star
46

deno_webidl

A toolbox for WebIDL, written for Deno.
TypeScript
2
star
47

gojs

JS running in Go using v8worker2 🤯
Go
2
star
48

deno_aws

AWS SDK for Deno
2
star
49

deno_analyzer

The analyzer used to score deno.land/x modules
TypeScript
2
star
50

frontmatter

handle frontmatter in files
Go
1
star
51

module-harmony-usecases

JavaScript
1
star
52

Go_Websocket

This is a go websocket api!
Go
1
star
53

stream-utils-demo

TypeScript
1
star
54

demooidc

TypeScript
1
star
55

test

1
star
56

date_extensions

Extensions to the default dart DateTime class
Dart
1
star
57

deploy_examples

JavaScript
1
star
58

dash-todo

A server rendered TODO application
TypeScript
1
star
59

modernfrontends2022-bench

JavaScript
1
star
60

tcq2

TypeScript
1
star
61

PayEnabledOrderSystem

PEOS is the standard for insecure transactions using Google Sheets
HTML
1
star
62

mf2-tools

This repo contains a language server for the Message Format 2 message localization system from Unicode.
Rust
1
star