puppeteer/examples
Andrey Lushnikov b73737302a
fix: convert all getters to methods (#1621)
The patch converts all the getters in the codebase into the methods.
For example, the `request.url` getter becomes the `request.url()`
method.

This is done in order to unify the API and make it more predictable.
The general rule for all further changes would be:
- there are no getters/fields exposed in the api
- the only exceptions are "namespaces", e.g. `page.keyboard`

Fixes #280.

BREAKING CHANGE:
This patch ditches getters and replaces them with methods throughout
the API. The following methods were added instead of the fields:
- dialog.type()
- consoleMessage.args()
- consoleMessage.text()
- consoleMessage.type()
- request.headers()
- request.method()
- request.postData()
- request.resourceType()
- request.url()
- response.headers()
- response.ok()
- response.status()
- response.url()
2017-12-18 17:05:57 -08:00
..
.eslintrc.js add 'use strict'; to examples (#530) 2017-08-24 17:33:41 -07:00
block-images.js fix: convert all getters to methods (#1621) 2017-12-18 17:05:57 -08:00
custom-event.js refactor: migrate NavigatorWatcher to lifecycle events (#1141) 2017-10-23 18:10:59 -07:00
detect-sniff.js refactor: migrate NavigatorWatcher to lifecycle events (#1141) 2017-10-23 18:10:59 -07:00
pdf.js refactor: migrate NavigatorWatcher to lifecycle events (#1141) 2017-10-23 18:10:59 -07:00
proxy.js chore(examples): Fixed a typo in examples/proxy.js (#1073) 2017-10-17 17:36:25 -07:00
README.md doc: Add headless-chrome-crawler to example's README (#1585) 2017-12-14 19:10:25 -08:00
screenshot-fullpage.js doc: add await to browser.close in usage examples (#797) 2017-09-15 21:27:14 -07:00
screenshot.js doc: add await to browser.close in usage examples (#797) 2017-09-15 21:27:14 -07:00
search.js chore(search) - search developers.google.com for "Headess chrome" articles (#1586) 2017-12-14 19:13:27 -08:00

Running the examples

Assuming you have a checkout of the Puppeteer repo and have run yarn (or npm i) to install the dependencies, the examples can be run from the root folder like so:

NODE_PATH=../ node examples/search.js

Tips & Tricks

Load a Chrome extension

By default, Puppeteer disables extensions when launching Chrome. You can load a specific extension using:

const browser = await puppeteer.launch({
  headless: false,
  args: [
    '--disable-extensions-except=/path/to/extension/',
    '--load-extension=/path/to/extension/',
  ]
});

Other resources

Other useful tools, articles, and projects that use Puppeteer.

Rendering and web scraping

  • Puppetron - Demo site that shows how to use Puppeteer and Headless Chrome to render pages. Inspired by GoogleChrome/rendertron.
  • Thal - Getting started with Puppeteer and Chrome Headless for Web Scraping.
  • pupperender - Express middleware that checks the User-Agent header of incoming requests, and if it matches one of a configurable set of bots, render the page using Puppeteer. Useful for PWA rendering.
  • headless-chrome-crawler - Crawler that provides simple APIs to manupluate Headless Chrome and allows you to crawl dynamic websites.

Testing