How to use the default function from puppeteer

Find comprehensive JavaScript puppeteer.default code examples handpicked from public code repositorys.

puppeteer.default is a Node library which provides a high-level API for controlling headless Chrome or Chromium over the DevTools Protocol.

6
7
8
9
10
11
12
13
14
15
const puppeteer_1 = __importDefault(require("puppeteer"));
const fs_1 = require("fs");
const server_1 = require("../server");
const scrape = async () => {
    try {
        const browser = await puppeteer_1.default.launch();
        const page = await browser.newPage();
        await page.goto('https://finance.yahoo.com/most-active/?offset=0&count=50');
        // Set screen size
        await page.setViewport({ width: 1920, height: 1080 });
fork icon0
star icon0
watch icon1

+ 8 other calls in file

93
94
95
96
97
98
99
100
101
102
}
login() {
    return __awaiter(this, void 0, void 0, function* () {
        console.log('[CF LOGIN] START');
        const loginUrl = 'https://codeforces.com/enter';
        const browser = yield puppeteer_1.default.launch({
            args: ['--no-sandbox'],
            timeout: 0,
        });
        const page = yield browser.newPage();
fork icon0
star icon0
watch icon1

+ 15 other calls in file

How does puppeteer.default work?

puppeteer.default is a JavaScript library that provides a high-level API for automating headless Chrome/Chromium browser tasks, including rendering pages to PDF and generating screenshots, controlling browser navigation, and interacting with page content. It works by launching a headless Chrome/Chromium instance and exposing a programmatic interface for controlling it.

7
8
9
10
11
12
13
14
15
16
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
var getPriceBs = /*#__PURE__*/function () {
  var _ref = _asyncToGenerator(function* () {
    var browser = yield _puppeteer.default.launch({
      headless: true
    });
    var page = yield browser.newPage();
    yield page.goto('https://www.bcv.org.ve');
fork icon0
star icon0
watch icon1

+ 28 other calls in file

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
const puppeteer = require("puppeteer");

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto("https://www.google.com");
  await page.type('input[name="q"]', "puppeteer");
  await page.keyboard.press("Enter");
  await page.waitForSelector("#search");
  await page.screenshot({ path: "screenshot.png" });
  await browser.close();
})();

This code launches a new headless Chrome browser with puppeteer.launch(), navigates to the Google homepage with page.goto(), types "puppeteer" into the search box and presses enter with page.type() and page.keyboard.press(), waits for the search results to appear with page.waitForSelector(), takes a screenshot of the page with page.screenshot(), and finally closes the browser with browser.close().