DEV Community

Custodia-Admin
Custodia-Admin

Posted on • Originally published at pagebolt.dev

How to Screenshot Any Webpage in Node.js Without Installing Chrome

You want to screenshot a webpage in Node.js. You google "nodejs screenshot" and find Puppeteer.

15 minutes later, you've installed Chromium (600MB), debugged headless browser crashes, and written this:

const puppeteer = require('puppeteer');

async function screenshot() {
  const browser = await puppeteer.launch({
    headless: true,
    args: ['--no-sandbox', '--disable-setuid-sandbox']
  });

  const page = await browser.newPage();
  await page.goto('https://example.com');
  await page.screenshot({path: 'screenshot.png'});
  await browser.close();
}

screenshot();
Enter fullscreen mode Exit fullscreen mode

There's a better way.

The Problem with Puppeteer

Puppeteer works, but it's overkill for simple screenshots:

  • Setup complexity: Install Chromium, configure sandboxing, handle crashes
  • Deployment pain: 600MB+ per container, slow cold starts, memory leaks
  • Maintenance burden: Browser crashes at 3am, logs fill with warnings

If you just need a screenshot, not full browser control, Puppeteer is overpowered.

The Solution: PageBolt REST API

Replace 15 lines of Puppeteer with 3 lines of HTTP:

const fetch = require('node-fetch');
const fs = require('fs');

async function screenshot() {
  const response = await fetch('https://api.pagebolt.com/screenshot', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      url: 'https://example.com',
      format: 'png',
      fullPage: true
    })
  });

  const buffer = await response.buffer();
  fs.writeFileSync('screenshot.png', buffer);
  console.log('Screenshot saved!');
}

screenshot();
Enter fullscreen mode Exit fullscreen mode

That's it. No Chrome. No setup. No crashes.

Real Comparison

Puppeteer approach:

  • 15 lines of code
  • 600MB Chromium download
  • Browser crashes to debug
  • 5-10 second latency per screenshot
  • Memory leaks at scale

PageBolt approach:

  • 3 lines of code
  • Zero setup
  • Zero crashes
  • 1-2 second latency
  • Scales automatically

Working Example: Batch Screenshots

Need to screenshot 100 URLs? Here's production-ready code:

const fetch = require('node-fetch');
const fs = require('fs');

async function screenshotBatch(urls) {
  const API_KEY = process.env.PAGEBOLT_API_KEY;
  const results = [];

  for (const url of urls) {
    try {
      const response = await fetch('https://api.pagebolt.com/screenshot', {
        method: 'POST',
        headers: {
          'Authorization': `Bearer ${API_KEY}`,
          'Content-Type': 'application/json'
        },
        body: JSON.stringify({
          url: url,
          format: 'png',
          fullPage: true
        })
      });

      if (!response.ok) {
        console.error(`Failed for ${url}: ${response.statusText}`);
        continue;
      }

      const buffer = await response.buffer();
      const filename = `screenshots/${new URL(url).hostname}.png`;
      fs.writeFileSync(filename, buffer);

      results.push({
        url: url,
        status: 'success',
        file: filename
      });

      console.log(`✓ ${url}`);
    } catch (error) {
      console.error(`Error: ${url} - ${error.message}`);
    }
  }

  return results;
}

// Usage
const urls = [
  'https://example.com',
  'https://google.com',
  'https://github.com'
];

screenshotBatch(urls).then(results => {
  console.log(`Completed: ${results.length} screenshots`);
});
Enter fullscreen mode Exit fullscreen mode

Why This Matters

For development:

  • Rapid iteration without Chrome setup
  • Works in Docker/serverless without 600MB bloat
  • No browser crash debugging

For production:

  • Simple REST API, proven at scale
  • Automatic retries and failover
  • Pay-per-use pricing (no server costs)

For DevOps:

  • Serverless-friendly (no persistent processes)
  • Zero infrastructure maintenance
  • Horizontal scaling built-in

When to Use PageBolt vs Puppeteer

Use PageBolt if:

  • You just need screenshots (no custom script execution)
  • You're running in Docker/serverless (want to avoid 600MB Chromium)
  • You need simple REST API (easier testing, monitoring)
  • You want zero maintenance (no browser crash debugging)

Use Puppeteer if:

  • You need full browser control (custom scripts, mouse movements)
  • You're running locally with dedicated resources
  • You want complete control over browser behavior

For 90% of screenshot use cases, PageBolt is simpler and faster.

Cost Comparison

Puppeteer (self-hosted):

  • Server cost: $50-200/mo (container, storage, CDN)
  • Engineering: 5-10 hours setup + maintenance
  • Total: $100-300/mo (including time)

PageBolt:

  • 5,000 screenshots/mo: $29
  • 25,000 screenshots/mo: $79
  • No setup, no maintenance

For small-scale use (< 50K screenshots/mo), PageBolt is cheaper and faster.

Next Step

Replace that Puppeteer code with PageBolt:

  1. Get API key at pagebolt.dev (free tier: 100 screenshots/mo)
  2. Swap 15 lines of Puppeteer with 3 lines of fetch
  3. Deploy without Chromium bloat

Your Node.js deployment just got 600MB lighter and infinitely simpler.

Try free: 100 screenshots/mo, no credit card. Test with your real URLs.


Canonical URL: https://pagebolt.dev/blog/screenshot-nodejs-without-chrome

Top comments (0)