Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ratson/puppeteer_plus
Deno port of puppeteer base on latest TypeScript source.
https://github.com/ratson/puppeteer_plus
automation deno headless-chrome puppeteer testing typescript web
Last synced: 23 days ago
JSON representation
Deno port of puppeteer base on latest TypeScript source.
- Host: GitHub
- URL: https://github.com/ratson/puppeteer_plus
- Owner: ratson
- License: mit
- Created: 2021-04-18T01:44:11.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-04-26T14:51:35.000Z (8 months ago)
- Last Synced: 2024-11-22T00:48:29.632Z (about 1 month ago)
- Topics: automation, deno, headless-chrome, puppeteer, testing, typescript, web
- Language: TypeScript
- Homepage: https://deno.land/x/puppeteer_plus
- Size: 3.48 MB
- Stars: 20
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# puppeteer_plus
An enhanced [Puppeteer](https://github.com/puppeteer/puppeteer) running on Deno.
## Features
- Add `await using` support for `Browser`, `Page`
- Download Browser executable when necessary
- Fix PDF writing error## Getting Started
### Installation
To use Puppeteer in your project,
```ts
import puppeteer from "https://deno.land/x/puppeteer_plus/mod.ts";
```### puppeteer-core
```ts
import puppeteer from "https://deno.land/x/puppeteer_plus/core.ts";
````puppeteer-core` is intended to be a lightweight version of Puppeteer for
launching an existing browser installation or for connecting to a remote one. Be
sure that the version of puppeteer-core you install is compatible with the
browser you intend to connect to.### 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](https://github.com/puppeteer/puppeteer/blob/main/docs/api.md).**Example** - navigating to https://example.com and saving a screenshot as
_example.png_:Save file as **example.js**
```ts
import puppeteer from "https://deno.land/x/puppeteer_plus/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
```bash
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()`](https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#pagesetviewportviewport).**Example** - create a PDF.
Save file as **hn.js**
```js
import puppeteer from "https://deno.land/x/puppeteer_plus/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
```bash
deno run -A --unstable hn.js
```See
[`Page.pdf()`](https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#pagepdfoptions)
for more information about creating pdfs.**Example** - evaluate script in the context of the page
Save file as **get-dimensions.js**
```js
import puppeteer from "https://deno.land/x/puppeteer_plus/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
```bash
deno run -A --unstable get-dimensions.js
```See
[`Page.evaluate()`](https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#pageevaluatepagefunction-args)
for more information on `evaluate` and related methods like
`evaluateOnNewDocument` and `exposeFunction`.## Known issues
- Resources is hold until 30 seconds timeout before exit, see
[#20179](https://github.com/denoland/deno/issues/20179)## Credits
`puppeteer_plus` is heavily inspired by
[`deno-puppeteer`](https://github.com/lucacasonato/deno-puppeteer), the key
difference is `puppeteer_plus` imports TypeScript version while `deno-puppeteer`
is using JavaScript with types.This project will definitely not exists without the great work of
[Puppeteer](https://github.com/puppeteer/puppeteer) prject.