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

To take recurring website screenshots with Playwright and Node.js, write a capture function that opens the page, saves an image, and closes the browser, then call it from a Node.js timer or an external scheduler. Use a timer for an approximate interval in a process that stays running; use an external scheduler when runs must happen independently of that process or follow a calendar schedule.

The examples below use Playwright’s regular Node.js API, so you do not need Playwright Test just to save screenshots.

Capture a website screenshot with Playwright

Install Playwright in a Node.js project and install its Chromium browser. From the project directory, run:

npm install playwright
npx playwright install chromium

Save this as capture.js. It creates the output directory, takes a full-page PNG, and closes the browser even if navigation or capture fails:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
const { chromium } = require('playwright');
const fs = require('node:fs/promises');
const path = require('node:path');

async function capture() {
  const outputDir = path.join(__dirname, 'screenshots');
  await fs.mkdir(outputDir, { recursive: true });

  const browser = await chromium.launch();
  try {
    const page = await browser.newPage();
    await page.goto('https://example.com', { waitUntil: 'load' });

    const filename = `capture-${new Date().toISOString().replace(/[:.]/g, '-')}.png`;
    await page.screenshot({
      path: path.join(outputDir, filename),
      fullPage: true,
    });
    console.log(`Saved ${filename} at ${new Date().toISOString()}`);
  } finally {
    await browser.close();
  }
}

capture().catch((error) => {
  console.error('Screenshot capture failed:', error);
  process.exitCode = 1;
});

Change the URL to the page you are authorized to capture. The timestamped name keeps later runs from overwriting earlier images. page.goto() waits for a navigation milestone, but it cannot establish that every application-specific or delayed element is ready. If the page renders content asynchronously, wait for a meaningful locator or application state before taking the screenshot rather than assuming one fixed delay suits every site. See the Playwright Page API and Playwright screenshots documentation.

Run captures repeatedly inside Node.js

For a simple worker that remains running, use a timer and await each capture before starting another. Handling an error inside each scheduled run lets later attempts continue:

const INTERVAL_MS = 60 * 60 * 1000; // approximately every hour

async function runScheduledCapture() {
  try {
    await capture();
  } catch (error) {
    console.error('Scheduled screenshot failed:', error);
  }
}

// Start with a capture now, then schedule later captures.
void runScheduledCapture();
const timer = setInterval(() => {
  void runScheduledCapture();
}, INTERVAL_MS);

// If your application needs to stop the schedule:
// clearInterval(timer);

Put this scheduling code in the same file after the capture function, or import that function from a module. The first call starts immediately; subsequent calls are scheduled at the interval. Since each callback awaits its own capture, a slow capture can still overlap a later timer tick if it takes longer than the interval. To prevent overlap, use a self-scheduling timeout that is set only after the current run finishes:

const INTERVAL_MS = 60 * 60 * 1000;

async function runAndScheduleNext() {
  try {
    await capture();
  } catch (error) {
    console.error('Scheduled screenshot failed:', error);
  } finally {
    setTimeout(() => {
      void runAndScheduleNext();
    }, INTERVAL_MS);
  }
}

void runAndScheduleNext();

This self-scheduling version waits the full interval after a run completes, so long captures shift the next run later. A setInterval timer instead targets recurring timer ticks, but does not promise exact timing. Node.js describes setInterval(callback, delay) as scheduling repeated execution; actual callback timing depends on event-loop work. A process-local timer also stops when its process exits. Consult the Node.js Timers API.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Choose a scheduling method

Approach Use it when Important trade-off
Node.js timer A long-running worker is already available and an approximate interval is acceptable. The process must stay alive; event-loop work affects timing. Add error logging and prevent overlapping captures if runs may take longer than the interval.
External scheduler or CI runner Runs should be launched independently of a particular Node.js process, or a calendar cadence is more suitable. You must configure the scheduler, persistence, and failure handling for your deployment. Scheduler-specific syntax and guarantees vary, so consult the service you use.

For an external schedule, make the Node.js script perform one capture and exit, then configure your chosen scheduler to invoke it. Ensure the output location persists beyond a temporary job environment if you need an archive. Decide how the scheduler reports failed jobs and whether it retries them; those behaviors are not provided by the capture function itself.

Choose what to capture and how to save it

Capture the viewport or the full page

For the visible viewport, use await page.screenshot({ path: 'screenshot.png' }). Add fullPage: true to capture the full scrollable page, as in the main example. Full-page capture can produce much taller images than a viewport capture.

Capture one element

Use a locator screenshot when you only need a chart, card, or other page region:

await page.locator('.report-panel').screenshot({ path: 'report-panel.png' });

Replace .report-panel with a selector that identifies the intended element. If the selector is not present or the element is not ready, the capture may fail; wait for the relevant locator or state before taking the screenshot.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Return image bytes instead of writing a file

Omit path to receive a buffer, for example when passing the image to an upload or processing step:

const imageBuffer = await page.screenshot({ fullPage: true });
// Pass imageBuffer to your storage or image-processing code.

Choose a naming and retention policy that matches your use: timestamps preserve each run, while a fixed filename keeps only the most recent image. Neither policy automatically removes old files; implement cleanup or storage retention separately.

Keep recurring captures useful and comparable

  • Choose a readiness condition. Wait for a meaningful selector or page state when a site loads content after navigation. There is no universal wait policy for every site.
  • Keep the capture environment stable for comparisons. Playwright notes that rendering can vary with host operating system, browser version, settings, hardware, power source, and headless mode. Pin or otherwise control the browser and operating-system environment when visual differences need to be meaningful. See Playwright visual comparisons.
  • Log each run. Record the target, time, and error so a missing image can be distinguished from a failed navigation or a stopped process.
  • Manage storage. Recurring full-page images accumulate. Decide whether to keep every run, rotate files, or move captures to persistent storage.
  • Choose a reasonable frequency. Check that repeated requests are permitted by the target site’s terms and appropriate for its service; the right cadence depends on the site.

Recurring image archive or visual regression test?

If the goal is to keep a sequence of images over time, use page.screenshot() and manage filenames and retention. If the goal is to detect changes against reviewed baseline images, use Playwright Test’s toHaveScreenshot(); that assertion is part of the Playwright test runner rather than the standalone screenshot API. A scheduled capture is not itself a baseline comparison.

Playwright Test retries rerun failed tests during a test run; they do not schedule new runs at a recurring cadence. Retries are off by default unless configured. See Playwright test retries.

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.
Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting recurring screenshots

The browser fails to launch

Confirm that the Playwright package and browser binaries are installed in the environment that runs the script. Run npx playwright install chromium in that environment, and check the runtime’s error output for any additional system requirements.

The page is blank or missing content

Check that navigation succeeded and the page reached the state your capture requires. Client-rendered or delayed content may need a locator or application-state wait after page.goto(). Avoid treating a generic sleep as proof that the page is ready.

Each scheduled run overwrites the previous image

Use a unique filename, such as the ISO timestamp in the example, or deliberately choose a fixed name if only the latest image should remain.

Captures overlap or drift from the intended cadence

If a capture can take longer than the interval, schedule the next run after the current one completes, or move execution to a scheduler suited to the cadence. Node.js timer callbacks are affected by event-loop work and should not be treated as exact wall-clock alarms.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

The screenshots differ even when the page appears unchanged

Keep the browser version, operating system, viewport, and other capture settings consistent. Differences in the host environment or rendering mode can change pixels; Playwright lists these among factors affecting browser rendering in its visual comparison guidance.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server. For one capture, call its API with a URL and save the returned image:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

See the ScreenshotNeo API documentation for request options. To make captures recurring, invoke this request from your existing scheduler or worker. ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before the shot; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots, and the free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Sign up for ScreenshotNeo and get 1,000 free screenshots a month with no card.

Frequently Asked Questions

Does a Playwright timer keep running after Node.js exits?

No. A timer created inside a Node.js process is process-local; use a running worker or an external scheduler to launch later captures.

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

Do I need Playwright Test to save a recurring screenshot?

No. The regular Playwright Page API can save screenshots from a standalone Node.js script. Playwright Test is relevant when you want test-runner features such as screenshot assertions.

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.