Home/Blog/software engineering
Back to all articles
software engineering#Puppeteer#Web Scraping#Web Automation

Web Automation & Data Scraping with Puppeteer: Headless Chrome, Stealth & PDF Generation

RB
Rajput BhavinArchitect
Founder, Rajput Bhavin Engineering
24 August 2026•11 min read

Quick Answer: Web Automation with Puppeteer#

⚡ Quick Answer / Executive Summary
Puppeteer is a Node.js library developed by Google that provides a high-level API to control headless Chrome/Chromium via the Chrome DevTools Protocol (CDP). It is the industry standard for automated data scraping from Single Page Applications (React/Next.js/Vue), automated PDF invoice/report rendering, screenshot generation, and headless form submission pipelines.

4 Production Use Cases for Puppeteer Automation#

At Rajput Bhavin Engineering, we build custom web automation and scraping engines across several high-impact business workflows:

Architecture Blueprint
System Flow
┌─────────────────────────────────────────────────────────────┐
│                 Puppeteer Production Use Cases              │
├─────────────────────┬───────────────────────────────────────┤
│ Dynamic Scraping    │ Extracting data from JS-rendered SPAs │
│ Automated PDF Gen   │ Generating pixel-perfect PDF invoices │
│ Synthetic E2E Tests │ Simulating multi-step user checkouts  │
│ Bot Task Execution  │ Submitting compliance forms & portals │
└─────────────────────┴───────────────────────────────────────┘

1. High-Performance SPA Scraping with Stealth#

Modern websites load data asynchronously via internal API calls and client-side JavaScript. Traditional HTML parsers (like Cheerio or BeautifulSoup) receive an empty

. Puppeteer executes the full browser rendering engine.

#Production Stealth Scraping Script:

TypeScript
Production Code
import puppeteer from 'puppeteer-extra';
import StealthPlugin from 'puppeteer-extra-plugin-stealth';

// Apply stealth plugin to bypass Cloudflare / Bot detection fingerprints
puppeteer.use(StealthPlugin());

export async function scrapeCompetitorPricing(targetUrl: string) {
  const browser = await puppeteer.launch({
    headless: true,
    args: [
      '--no-sandbox',
      '--disable-setuid-sandbox',
      '--disable-dev-shm-usage', // Prevents memory crashes in Docker
      '--disable-accelerated-2d-canvas',
      '--disable-gpu',
    ],
  });

  const page = await browser.newPage();

  // Set realistic viewport & user agent
  await page.setViewport({ width: 1920, height: 1080 });
  await page.setUserAgent(
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36'
  );

  // Block unnecessary assets (images, stylesheets, fonts) to accelerate scraping by 4x
  await page.setRequestInterception(true);
  page.on('request', (req) => {
    if (['image', 'stylesheet', 'font', 'media'].includes(req.resourceType())) {
      req.abort();
    } else {
      req.continue();
    }
  });

  try {
    await page.goto(targetUrl, { waitUntil: 'networkidle2', timeout: 30000 });

    // Wait for the dynamic price element
    await page.waitForSelector('[data-testid="product-price"]', { timeout: 5000 });

    const products = await page.evaluate(() => {
      const items = Array.from(document.querySelectorAll('.product-card'));
      return items.map((el) => ({
        title: el.querySelector('h2')?.textContent?.trim() || '',
        price: el.querySelector('.price')?.textContent?.trim() || '',
      }));
    });

    return products;
  } finally {
    await browser.close();
  }
}

2. Automated Pixel-Perfect PDF Report Generation#

Generate formatted invoices, audit certificates, or analytics summaries using raw HTML and CSS print stylesheets:

TypeScript
Production Code
import puppeteer from 'puppeteer';

export async function generateInvoicePdf(htmlContent: string): Promise<Buffer> {
  const browser = await puppeteer.launch({ headless: true, args: ['--no-sandbox'] });
  const page = await browser.newPage();

  await page.setContent(htmlContent, { waitUntil: 'networkidle0' });

  const pdfBuffer = await page.pdf({
    format: 'A4',
    printBackground: true,
    margin: {
      top: '20mm',
      bottom: '20mm',
      left: '15mm',
      right: '15mm',
    },
  });

  await browser.close();
  return Buffer.from(pdfBuffer);
}

4 Best Practices for Headless Browser Pipelines#

  1. ✓Always Use --disable-dev-shm-usage in Docker: By default, Docker allocates 64MB of shared memory (/dev/shm), which causes Chromium to crash on heavy pages. This flag forces Chromium to use /tmp disk storage instead.
  2. ✓Reuse Browser Instances (Connection Pooling): Launching a new Chromium browser process consumes ~150MB of RAM and 1.5 seconds of CPU time. In high-concurrency apps, maintain a pool of warm browser tabs rather than launching new processes per request.
  3. ✓Always Close Pages and Browsers in finally Blocks: Unhandled script errors will leave zombie Chromium processes running in the background, eventually exhausting server memory.
  4. ✓Proxy Rotation for Large-Scale Data Mining: Route requests through residential proxy pools (BrightData, Oxylabs) with automatic IP rotation to avoid rate limits.

Custom Web Automation & Data Pipelines with Rajput Bhavin#

Need automated web scrapers, data extraction pipelines, or headless browser workflows engineered for your enterprise?

Workflow & Web Automation

Need automation for your business processes?

Rajput Bhavin Engineering builds custom AI-powered automation systems, web scrapers, workflow bots, and real-time data pipelines for enterprises across industries.

RB

Rajput Bhavin

Systems Architect

Founder and Systems Architect at Rajput Bhavin Engineering in Gota, Ahmedabad. Specializes in high-concurrency cloud software, Next.js web applications, multi-tenant SaaS architecture, and autonomous AI systems.

Connect Now