Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork46
A port of puppeteer running on Deno
License
lucacasonato/deno-puppeteer
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A fork ofPuppeteer 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 runsheadless by default, but can be configured to run full (non-headless) Chromeor 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 directlyin the latest version of Chrome using the latest JavaScript and browserfeatures.
- Capture a timeline trace of your site to help diagnose performance issues.
- Test Chrome Extensions.
To use Puppeteer, import it like so:
importpuppeteerfrom"https://deno.land/x/puppeteer@16.2.0/mod.ts";
Puppeteer can use any recent version of Chromium or Firefox Nightly, but thisversion of Puppeteer is only validated against a specific version. To cachethese versions in the Puppeteer cache, run the commands below.
PUPPETEER_PRODUCT=chrome deno run -A --unstable https://deno.land/x/puppeteer@16.2.0/install.tsPUPPETEER_PRODUCT=firefox deno run -A --unstable https://deno.land/x/puppeteer@16.2.0/install.ts
You can find all of the supported environment variables to customizeinstallationin the Puppeteer docs.
Puppeteer will be familiar to people using other browser testing frameworks. Youcreate an instance ofBrowser, open pages, and then manipulate them withPuppeteer's API.
Example - navigating tohttps://example.com and saving a screenshot asexample.png:
Save file asexample.js
importpuppeteerfrom"https://deno.land/x/puppeteer@16.2.0/mod.ts";constbrowser=awaitpuppeteer.launch();constpage=awaitbrowser.newPage();awaitpage.goto("https://example.com");awaitpage.screenshot({path:"example.png"});awaitbrowser.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 screenshotsize. The page size can be customized withPage.setViewport().
Example - create a PDF.
Save file ashn.js
importpuppeteerfrom"https://deno.land/x/puppeteer@16.2.0/mod.ts";constbrowser=awaitpuppeteer.launch();constpage=awaitbrowser.newPage();awaitpage.goto("https://news.ycombinator.com",{waitUntil:"networkidle2",});awaitpage.pdf({path:"hn.pdf",format:"A4"});awaitbrowser.close();
Execute script on the command line
deno run -A --unstable hn.js
SeePage.pdf()for more information about creating pdfs.
Example - evaluate script in the context of the page
Save file asget-dimensions.js
importpuppeteerfrom"https://deno.land/x/puppeteer@16.2.0/mod.ts";constbrowser=awaitpuppeteer.launch();constpage=awaitbrowser.newPage();awaitpage.goto("https://example.com");// Get the "viewport" of the page, as reported by the page.constdimensions=awaitpage.evaluate(()=>{return{width:document.documentElement.clientWidth,height:document.documentElement.clientHeight,deviceScaleFactor:window.devicePixelRatio,};});console.log("Dimensions:",dimensions);awaitbrowser.close();
Execute script on the command line
deno run -A --unstable get-dimensions.js
deno-puppeteer effectively runs a regular version of Puppeteer, except forsome minor changes to make it compatible with Deno.
The most noticable difference is likely that instead of some methods taking /returning NodeBuffer, they take / returnUint8Array. One method alsoreturns a web nativeReadableStream instead of the NodeReadable.
Other than this, the documentation onhttps://pptr.dev generally applies.
An example Dockerfile can be found in this repository. It will install allnecessary dependencies, and shows how to run the ./examples/docker.js.
It is just meant as a jumping off point - customize it as you wish.
About
A port of puppeteer running on Deno
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Contributors7
Uh oh!
There was an error while loading.Please reload this page.
