In this session, I will discuss the use of puppeteer for implementing a simple feature of export to pdf. We will also discuss some of the problems that one can face, and how they can be resolved.
2. Lack of etiquette and manners is a huge turn off.
KnolX Etiquettes
Punctuality
Respect Knolx session timings, you
are requested not to join sessions
after a 5 minutes threshold post
the session start time.
Feedback
Make sure to submit a constructive
feedback for all sessions as it is
very helpful for the presenter.
Silent Mode
Keep yourself muted until and
unless you have any query.
3. Our Agenda
1. Node.js
2. Node modules
3. NPM(Node Package Manager)
4. HandleBars
5. Introduction to Puppeteer
6. Demo
7. Problems with Puppeteer and their Solution
4. Node.js
● Node.js is an open source server environment.
● Node.js runs on various platforms (Windows, Linux, Unix, Mac OS, etc.).
● Node.js uses JavaScript on the server.
● Node.js is asynchronous.
● Node.js is single-threaded and highly scalable.
5. Node Module
● Node module is a functionality organized in single or multiple JavaScript files which
can be reused throughout the Node.js application.
● Each module in Node.js has its own context.
6. NPM(Node Package Manager)
● NPM is a repository where we have a large
number of node modules available.
● It is also a command line utility, to install these
node modules.
● For installing : npm install module_name
7. HandleBars
● HandleBars is a node module which is used to create html templates.
● It uses a template and a data object to generate HTML page.
● To install : npm install handlebars
● For example :
Input
Template HTML
8. Introduction to Puppeteer
According to the documentation :
Puppeteer is a Node library which provides a high-level API to control Chrome or
Chromium over the DevTools Protocol. Puppeteer runs headless by default, but
can be configured to run full (non-headless) Chrome or Chromium.
9. Usage of Puppeteer
● 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.
● Test Chrome Extensions.
12. Problems with Puppeteer
and their Solution
● Loading of an image
Rather than directly passing the data, create an html page and goto that
page to create PDF.
● Problem with chromium available in puppeteer on EC2 instances
Install chromium on EC2 instance explicitly. Set chromium path to the
chromium installed. And now instead of puppeteer use puppeteer-core.