Task Development

Learn how to code DEX8 Tasks

Puppeteer

One of the most important libraries is Puppeteer.
puppeteer
It is the library which takes control of the web browser and automate tasks.

Installation

To install puppeteer without Chromium browser use: $ npm run inst

To install puppeteer with Chromium use: $ npm run inst-chromium

Usage

The best example of how to use it is here.
This example shows how to extract data from a single web page.

Notice that puppeteer should be added by using libAdd() FunctionFlow method in the main.js file.
main.js
------------------
const puppeteer = require('puppeteer');

module.exports = async (input, lib) => {
  const ff = lib.ff;
  ff.libAdd({puppeteer});
};

After such injection Puppeteer can be used in every function as lib.puppeteer .
f1.js
------------------
const sysconfig = require('./sysconfig.js');

module.exports = async (x, lib) => {
  const ff = lib.ff;

  const browser = await lib.puppeteer.launch(sysconfig.puppeteer);
  const page = await browser.newPage();
  page.emulate(sysconfig.device);
  await page.bringToFront();
  await page.setViewport({width: sysconfig.viewport.width, height: sysconfig.viewport.height});

  ff.libAdd({browser, page});
  return x;
};