Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For server-side HTML screenshots in Node.js, use Playwright or Puppeteer: both drive a real browser, unlike html2canvas, which depends on browser APIs and reconstructs an image from DOM and style information. Start with Playwright if its browser and capture options fit your application; consider Puppeteer if it better matches your existing automation stack. Neither guarantees pixel-perfect output: page state, fonts, assets, browser, viewport, and capture settings all matter.

Why html2canvas does not work as a Node.js screenshot tool

html2canvas is designed to run in a browser, where it can access browser globals and APIs. Its documentation describes a process that traverses the DOM and builds a representation of the page; it does not take a literal screenshot of the browser’s rendered pixels. That distinction explains both its appeal for client-side captures and its limits for server-side rendering. html2canvas documentation

Because it recreates the image from DOM and style information it understands, the result can differ from the page as rendered by a browser. Its FAQ notes that CSS properties need individual implementation and that complete CSS support is not possible. Adding a Node.js wrapper does not supply the missing browser context or turn this DOM reconstruction into an actual browser capture.

Security restrictions also affect its input: browser policy can prevent reading cross-origin images, and cross-origin iframes cannot be read. These are important constraints when the page includes third-party assets or embedded content. html2canvas FAQ

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What to use instead: a headless browser

For a Node.js process that needs an image of a URL or rendered markup, use browser automation. Playwright and Puppeteer launch or connect to a browser, let it render the page, and expose screenshot methods. The html2canvas FAQ itself points server-side users toward these tools. html2canvas FAQ

This is a change in approach, not a promise of identical output across environments. Fonts may not have loaded, images may still be in flight, JavaScript may be changing the page, or a viewport and browser engine may produce different layout. Set readiness and capture options deliberately, then validate representative pages in the deployment environment.

Playwright: a strong default for server-side captures

Playwright’s Page screenshot API supports capture configuration, while its screenshot guide covers the visible viewport, an element, and the full scrollable page. That makes it a practical choice when your Node.js service needs to choose capture scope and output behavior as part of its workflow. Playwright screenshots guide · Playwright Page API

Use a browser engine and runtime setup that match the application’s deployment needs. For dynamic pages, wait for a meaningful page condition—such as a specific selector—rather than assuming navigation alone means the content is ready. The right readiness condition depends on the page.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Install and capture a viewport screenshot

In a new Node.js project, install Playwright and its browser:

Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
npm install playwright
npx playwright install chromium

Save this as screenshot.mjs, then run it with node screenshot.mjs https://example.com. Replace the URL with a page you are authorized to capture.

import { chromium } from 'playwright';

const url = process.argv[2];
if (!url) throw new Error('Usage: node screenshot.mjs <url>');

const browser = await chromium.launch({ headless: true });
try {
  const page = await browser.newPage({
    viewport: { width: 1440, height: 900 }
  });
  await page.goto(url, { waitUntil: 'networkidle', timeout: 30000 });
  await page.screenshot({ path: 'screenshot.png', fullPage: true });
} finally {
  await browser.close();
}

This example produces a PNG of the full page after navigation reaches network idle. Some sites keep network activity open, so a network-idle wait may be unsuitable there; use a selector or another condition that reflects when the particular page is ready. If you only need the current viewport, omit fullPage: true.

Capture a specific element

Use a locator to scope the screenshot to an element. This example waits for a matching element and saves it:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const card = page.locator('.report-card');
await card.waitFor({ state: 'visible' });
await card.screenshot({ path: 'report-card.png' });

Choose a selector that uniquely identifies the intended content. A selector that matches nothing, matches the wrong element, or stays hidden will prevent a useful capture.

Choose output format and scope deliberately

Playwright’s screenshot configuration supports output type and capture options. Use a file extension and type that agree with the consumer of the image. Full-page capture is useful for a long document; viewport capture is more predictable when the output must have a fixed size. Element capture avoids surrounding page content. Consult the Page screenshot API for the available options and their exact behavior.

Puppeteer: another direct Node.js option

Puppeteer is also named by the html2canvas FAQ as a server-side alternative. Its Page screenshot method returns image bytes, so a Node.js application can write the result to a file or pass the bytes to another part of its pipeline. Puppeteer Page.screenshot API

Choose Puppeteer when its browser support, API, deployment requirements, and compatibility with the rest of your automation stack suit the project. Its API documentation also describes coordination behavior when a screenshot is already in progress in a BrowserContext; account for that if your application schedules concurrent capture work.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Install and capture with Puppeteer

Install Puppeteer, which manages a compatible browser installation as part of its standard setup:

npm install puppeteer

Save the following as screenshot.mjs and run node screenshot.mjs https://example.com:

import puppeteer from 'puppeteer';
import { writeFile } from 'node:fs/promises';

const url = process.argv[2];
if (!url) throw new Error('Usage: node screenshot.mjs <url>');

const browser = await puppeteer.launch({ headless: true });
try {
  const page = await browser.newPage();
  await page.setViewport({ width: 1440, height: 900 });
  await page.goto(url, { waitUntil: 'networkidle0', timeout: 30000 });
  const bytes = await page.screenshot({ fullPage: true, type: 'png' });
  await writeFile('screenshot.png', bytes);
} finally {
  await browser.close();
}

As with Playwright, choose the navigation and readiness condition based on the site. A page that continually polls or loads content after initial navigation may need a different wait condition or an explicit wait for the content being captured.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

How to choose between Playwright and Puppeteer

The documentation establishes capabilities, not a universal speed, accuracy, or cost winner. Compare both against the pages and runtime you actually need to support.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Decision point What to check
Browser requirements Which browser engines and versions your application and deployment environment need to run.
Capture scope Whether you need a viewport, one element, or the full scrollable page.
Output and controls Required image type, viewport, and screenshot options; confirm exact behavior in the tool’s API documentation.
Page readiness How the target pages signal that fonts, images, and dynamic content needed for the capture are ready.
Operations Browser installation, process lifecycle, isolation, concurrency, and compatibility with the existing test or automation stack.

If those criteria do not settle the choice, prototype the required capture in both tools using representative pages, including pages with the real fonts, images, and JavaScript. Compare the images and how each tool behaves in your target runtime; documentation alone cannot establish which will work better for your specific workload.

Or skip the browser setup

If you would rather not install and manage a browser in your Node.js service, ScreenshotNeo is a hosted website screenshot API with an MCP server for AI agents. Send one GET request with a URL to get an image or PDF. For example, using Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

See the ScreenshotNeo API documentation for setup and response details. Cookie banners are accepted before capture, and known consent platforms, newsletter popups, and chat widgets can be removed. Bot checks, blank pages, and failed loads are never billed; responses identify page verdict and billing status. Its MCP server gives AI agents tools to take screenshots, get page information, and capture PDFs. The free plan includes 1,000 screenshots a month without a card; paid plans start at $5 for 3,000.

Sign up free for 1,000 screenshots a month, with no card required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Common problems and fixes

The screenshot is blank or missing content

  • Check that navigation completed and the expected page loaded; a successful navigation call does not prove the right content is present.
  • Wait for a content-specific selector when the page fills in after navigation.
  • Check whether the content is inside an iframe or depends on a login, interaction, or remote asset that is unavailable to the browser session.

The capture times out

  • Confirm the URL is reachable from the machine running Node.js and that the timeout is sufficient for the page.
  • If network-idle waiting never completes because the page keeps making requests, wait for a specific selector or use a more suitable readiness condition.

The layout differs from a local browser view

  • Set the viewport explicitly and compare the same browser engine and page state.
  • Ensure the required fonts and images have loaded before capturing.
  • Remember that dynamic content, browser configuration, and capture scope can change the output; validate the result in the target runtime.

Installation or launch fails in deployment

  • Verify that the browser expected by the automation package is installed and available in the deployment environment.
  • Check the runtime’s process and isolation constraints, then follow the chosen tool’s installation guidance for that environment.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Cost, performance, and reliability considerations

With Playwright or Puppeteer, your application operates the browser process and must account for its installation, lifecycle, and concurrency. The cited APIs do not establish a performance winner. Measure the work that matters in your own runtime: page-load and readiness time, browser resource use, throughput under expected concurrency, and the impact of failures or retries.

A hosted screenshot API avoids managing the browser installation yourself, but it introduces a service dependency and requires checking its output options, billing behavior, data handling, and terms against your needs. ScreenshotNeo’s published plans and billing behavior are described above; assess whether a hosted service is suitable for the pages and information you intend to capture.

Which approach fits?

  • Use html2canvas when capture happens in a browser and a DOM-derived representation is acceptable.
  • Use Playwright or Puppeteer for server-side Node.js screenshots rendered by an automated browser.
  • Use a hosted screenshot API if avoiding browser setup is more important than operating the capture stack yourself.

Frequently Asked Questions

Can I make html2canvas run on a Node.js server by wrapping it?

No wrapper changes its reliance on browser APIs or its DOM-reconstruction approach. For server-side browser rendering, use Playwright or Puppeteer.

Will Playwright or Puppeteer reproduce every browser pixel exactly?

No. The result depends on page state, assets, fonts, browser, viewport, and capture configuration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Which one is faster, Playwright or Puppeteer?

The cited documentation does not establish a universal performance winner. Benchmark representative pages in your intended runtime if speed is decisive.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.