How to use puppeteer

Comprehensive puppeteer code examples:

How to use puppeteer._preferredRevision:

56
57
58
59
60
61
62
63
64
65
if (pptrPackageJSON.puppeteer) {
  return pptrPackageJSON.puppeteer.chromium_revision;
}

if (puppeteer._preferredRevision) {
  return puppeteer._preferredRevision;
}

const pptr = require('./node_modules/puppeteer-core/lib/cjs/puppeteer/revisions');
return pptr.PUPPETEER_REVISIONS.chromium;

How to use puppeteer.defaultArgs:

616
617
618
619
620
621
622
623
624
625

});

  }else{ // OPTION 2: use local machine browsers

var args = puppeteer.defaultArgs();
args = puppeteer.defaultArgs().filter(arg => arg !== '--disable-dev-shm-usage')
args.push(
		"--disable-setuid-sandbox",
		'--no-sandbox',

How to use puppeteer.devices:

147
148
149
150
151
152
153
154
155
if (request.options && request.options.userAgent) {
    await page.setUserAgent(request.options.userAgent);
}

if (request.options && request.options.device) {
    const devices = puppet.devices;
    const device = devices[request.options.device];
    await page.emulate(device);
}

How to use puppeteer.Browser:

0
1
2
3
4
5
6
7
8
9
10
11
12
const express = require('express')
const puppeteer = require('puppeteer')
const app = express()


let page = puppeteer.Page
let browser = puppeteer.Browser


let hrefs = []


app.use(express.static('public'));

How to use puppeteer.Page:

How to use puppeteer.use:

38
39
40
41
42
43
44
45
46
47
    require('puppeteer-extra-plugin-stealth/evasions/webgl.vendor');
    require('puppeteer-extra-plugin-stealth/evasions/window.outerdimensions');
    require('puppeteer-extra-plugin-user-preferences');
    require('puppeteer-extra-plugin-user-data-dir');

    puppeteer.use(require('puppeteer-extra-plugin-stealth')());
}
let browser;
if (proxyUri) {
    if (proxyUrlHandler.username || proxyUrlHandler.password) {

How to use puppeteer.createBrowserFetcher:

72
73
74
75
76
77
78
79
80
81
82
83
const PUPPETEER_BINARY_LOCATION = (() => {
  if (PLATFORM === LINUX_ARM64) {
    return playwright.chromium.executablePath();
  }


  const browserFetcher = puppeteer.createBrowserFetcher({ product: 'chrome' });


  return browserFetcher.revisionInfo(PUPPETEER_CHROMIUM_REVISION)
    .executablePath;
})();

How to use puppeteer.default:

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 });

How to use puppeteer.errors:

131
132
133
134
135
136
137
138
139
140
        //console.log('EMPTY RESULT')
        //continuousEmpty++
    //}
    //continuousErrors = 0
} catch (e) {
  if (e ) { //instanceof puppeteer.errors.TimeoutError) {
    // Do something if this is a timeout.
    //continuousErrors ++
    console.log('ERR',e)
  }

How to use puppeteer.executablePath:

51
52
53
54
55
56
57
58
59
60
61
62
63


const domain = '@domain.net'
let email, username, password


puppeteer.launch({
    headless: false, executablePath: executablePath()
}).then(async browser => {


    username = 'username1234' + Math.floor(Math.random() * 100)
    email = username + domain

How to use puppeteer.connect:

602
603
604
605
606
607
608
609
610
611
    'browserstack.accessKey': browserstack_password || 'YOUR_DEFAULT_ACCESS_KEY',
    'browserstack.local': 'true'  // setting this capability to true would inform BrowserStack that publicly inaccessible URLs have to be resolved through your local network using the tunnel connection created by 'browserstack-local' node package
};

// use `.connect()` to initiate an Automate session on BrowserStack
const browser = await puppeteer.connect({
    browserWSEndpoint: `wss://cdp.browserstack.com/puppeteer?caps=${encodeURIComponent(JSON.stringify(capabilities))}`,
});

await start_dynamic_analysis(browser, webpage_path, website_url, website_data_directory);

How to use puppeteer.launch:

49
50
51
52
53
54
55
56
57
58
59
60
  address = family === 'IPv6' ? `[${address}]` : address
  return `http://${address}:${port}`
}


const download = async (baseDir, url) => {
  const browser = await puppeteer.launch()
  const page = await browser.newPage()
  const urls = []


  page.on('request', (request) => {