<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Vitalii Holben</title>
    <description>The latest articles on DEV Community by Vitalii Holben (@webmox).</description>
    <link>https://dev.to/webmox</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3842314%2F73646452-030c-4c9e-8633-79bbc79167fe.jpg</url>
      <title>DEV Community: Vitalii Holben</title>
      <link>https://dev.to/webmox</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/webmox"/>
    <language>en</language>
    <item>
      <title>Building a Simple Website Change Detection Pipeline with Python</title>
      <dc:creator>Vitalii Holben</dc:creator>
      <pubDate>Tue, 24 Nov 2026 13:48:00 +0000</pubDate>
      <link>https://dev.to/webmox/building-a-simple-website-change-detection-pipeline-with-python-3ajh</link>
      <guid>https://dev.to/webmox/building-a-simple-website-change-detection-pipeline-with-python-3ajh</guid>
      <description>&lt;p&gt;Needed to track changes on a handful of web pages for a project last month. Nothing fancy — just know when content on specific URLs changes. Ended up building a quick pipeline that I figured might be useful to share.&lt;/p&gt;

&lt;h2&gt;The basic idea&lt;/h2&gt;

&lt;p&gt;Fetch page, hash the content, compare to previous hash, notify if different. Classic.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;import hashlib
import requests
import json
from pathlib import Path

URLS = [
    'https://example.com/pricing',
    'https://example.com/features',
]

STATE_FILE = Path('page_states.json')

def load_state():
    if STATE_FILE.exists():
        return json.loads(STATE_FILE.read_text())
    return {}

def save_state(state):
    STATE_FILE.write_text(json.dumps(state, indent=2))

def get_page_hash(url):
    resp = requests.get(url, timeout=30)
    return hashlib.sha256(resp.text.encode()).hexdigest()
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Simple enough. Run it on a cron, done.&lt;/p&gt;

&lt;p&gt;Except not really.&lt;/p&gt;

&lt;h2&gt;The problems you hit immediately&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Dynamic content.&lt;/strong&gt; Most modern pages include timestamps, session tokens, CSRF tokens, ad scripts that change on every request. Your hash changes every single time even when the actual content is identical.&lt;/p&gt;

&lt;p&gt;Fix: strip the noise before hashing.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;from bs4 import BeautifulSoup
import re

def normalize_page(html):
    soup = BeautifulSoup(html, 'html.parser')
    
    # Remove scripts and styles
    for tag in soup(['script', 'style', 'noscript']):
        tag.decompose()
    
    # Remove elements that change every load
    for el in soup.select('[data-timestamp], [data-session], .ad-container'):
        el.decompose()
    
    text = soup.get_text(separator=' ', strip=True)
    # Collapse whitespace
    return re.sub(r'\s+', ' ', text).strip()
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This gets you maybe 80% of the way. Some sites are worse than others.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JavaScript-rendered content.&lt;/strong&gt; If the page relies on JS to load content (basically every SPA), requests.get gives you an empty shell. You need a real browser.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;from playwright.sync_api import sync_playwright

def get_rendered_html(url):
    with sync_playwright() as p:
        browser = p.chromium.launch()
        page = browser.new_page()
        page.goto(url, wait_until='networkidle')
        html = page.content()
        browser.close()
        return html
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Works but now you need Chromium installed, and each page fetch takes 3-10 seconds instead of 200ms.&lt;/p&gt;

&lt;h2&gt;Where I actually landed&lt;/h2&gt;

&lt;p&gt;For the 5 pages I needed to monitor, the full pipeline looks like:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Playwright fetches rendered HTML&lt;/li&gt;
&lt;li&gt;BeautifulSoup strips dynamic elements&lt;/li&gt;
&lt;li&gt;Hash the normalized text&lt;/li&gt;
&lt;li&gt;Compare against stored state&lt;/li&gt;
&lt;li&gt;Send a Slack webhook if changed&lt;/li&gt;
&lt;/ol&gt;

&lt;pre&gt;&lt;code&gt;def check_pages():
    state = load_state()
    changes = []
    
    for url in URLS:
        html = get_rendered_html(url)
        normalized = normalize_page(html)
        current_hash = hashlib.sha256(normalized.encode()).hexdigest()
        
        prev_hash = state.get(url)
        if prev_hash and prev_hash != current_hash:
            changes.append(url)
        
        state[url] = current_hash
    
    save_state(state)
    
    if changes:
        notify_slack(changes)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Total code is under 100 lines. Runs in a GitHub Action every 6 hours. Free tier covers it easily.&lt;/p&gt;

&lt;h2&gt;Limitations (being honest)&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;No visual diff — you know something changed but not what exactly&lt;/li&gt;
&lt;li&gt;BeautifulSoup normalization is brittle — new ad scripts or tracking pixels can cause false positives&lt;/li&gt;
&lt;li&gt;Playwright in GitHub Actions adds ~30s startup overhead&lt;/li&gt;
&lt;li&gt;No history — just current vs previous, cant see when changes happened over time&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For my use case this was fine. If I needed visual diffs, change history, or monitoring more than ~20 pages, I'd probably reach for a dedicated tool instead of maintaining this myself.&lt;/p&gt;

&lt;p&gt;Anyone running something similar? Curious what normalization strategies work for you.&lt;/p&gt;

</description>
      <category>websitemonitoring</category>
      <category>screenshot</category>
      <category>archive</category>
      <category>changedetection</category>
    </item>
    <item>
      <title>Stop Writing Cron Jobs That Fail Silently</title>
      <dc:creator>Vitalii Holben</dc:creator>
      <pubDate>Tue, 24 Nov 2026 13:29:03 +0000</pubDate>
      <link>https://dev.to/webmox/stop-writing-cron-jobs-that-fail-silently-4lep</link>
      <guid>https://dev.to/webmox/stop-writing-cron-jobs-that-fail-silently-4lep</guid>
      <description>&lt;p&gt;Every team I've worked with has at least one cron job that failed weeks ago and nobody noticed. The nightly database cleanup that stopped running after a server migration. The report generator that's been throwing errors into /dev/null since someone changed the DB password.&lt;/p&gt;

&lt;p&gt;The pattern is always the same: cron runs, something breaks, cron doesn't run anymore, silence.&lt;/p&gt;

&lt;h2&gt;Why cron fails quietly&lt;/h2&gt;

&lt;p&gt;Cron itself doesn't have a concept of "this job should have run but didn't". It fires based on schedule. If the process exits with an error, cron doesn't care. If the server was down during the scheduled time, cron doesn't retry.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;# This will fail silently forever if backup.sh exits non-zero
0 2 * * * /opt/scripts/backup.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Most people add email notifications:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;MAILTO=ops@company.com
0 2 * * * /opt/scripts/backup.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Which works until your mail server is also the thing that broke. Or until the ops mailbox has 4000 unread cron emails and nobody checks it anymore.&lt;/p&gt;

&lt;h2&gt;The dead man's switch approach&lt;/h2&gt;

&lt;p&gt;Better pattern: instead of alerting on failure, alert on the &lt;em&gt;absence of success&lt;/em&gt;. Your cron job pings a URL after completing successfully. If the ping doesn't arrive within the expected window, something's wrong.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;0 2 * * * /opt/scripts/backup.sh &amp;amp;&amp;amp; curl -fsS https://your-monitor/ping/abc123 &amp;gt; /dev/null
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; matters — the ping only fires if backup.sh exits 0. If the script fails, no ping. If the server is down, no ping. If cron itself is broken, no ping. All three scenarios trigger an alert.&lt;/p&gt;

&lt;h2&gt;What to monitor (and what to skip)&lt;/h2&gt;

&lt;p&gt;Not every cron needs monitoring. Here's how I think about it:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Always monitor:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Database backups (you'll regret it if you don't)&lt;/li&gt;
&lt;li&gt;Payment processing jobs&lt;/li&gt;
&lt;li&gt;Data sync between systems&lt;/li&gt;
&lt;li&gt;Certificate renewal scripts&lt;/li&gt;
&lt;li&gt;Anything that runs less than daily — easy to miss&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Probably skip:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Log rotation (OS handles recovery)&lt;/li&gt;
&lt;li&gt;Cache warmers (self-healing usually)&lt;/li&gt;
&lt;li&gt;Dev environment tasks&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Grace periods matter&lt;/h2&gt;

&lt;p&gt;Don't set your alert threshold to exactly your cron interval. If your backup runs at 2 AM and usually takes 20 minutes, don't alert at 2:01 AM. Give it a grace period — maybe alert if it hasn't pinged by 3 AM.&lt;/p&gt;

&lt;p&gt;Jobs that run on loaded servers will occasionally take 2x or 3x longer. You want to catch actual failures, not slow runs.&lt;/p&gt;

&lt;h2&gt;The overnight test&lt;/h2&gt;

&lt;p&gt;Here's something I do with any new monitoring setup: set up the monitor, then intentionally break the cron job. Comment it out, or make the script exit 1. Wait for the alert. If it comes within the expected timeframe, you're good. If it doesn't, your monitoring has a gap.&lt;/p&gt;

&lt;p&gt;Sounds basic but I've seen teams set up monitoring dashboards that look great and never actually verified they fire alerts.&lt;/p&gt;

&lt;p&gt;Anyone else have war stories about silent cron failures? The worst one I've seen was a backup job that had been writing to a full disk for 6 months — zero-byte backups, no errors, no alerts.&lt;/p&gt;

</description>
      <category>cronmonitoring</category>
      <category>scheduledtasks</category>
      <category>uptime</category>
      <category>devops</category>
    </item>
    <item>
      <title>I Tested 4 Browser Rendering Approaches for Screenshots — Here's What Actually Worked</title>
      <dc:creator>Vitalii Holben</dc:creator>
      <pubDate>Tue, 24 Nov 2026 13:24:16 +0000</pubDate>
      <link>https://dev.to/webmox/i-tested-4-browser-rendering-approaches-for-screenshots-heres-what-actually-worked-44d0</link>
      <guid>https://dev.to/webmox/i-tested-4-browser-rendering-approaches-for-screenshots-heres-what-actually-worked-44d0</guid>
      <description>&lt;p&gt;I spent way too long last quarter evaluating how to generate screenshots programmatically. Not for fun — we needed reliable page captures for a visual regression pipeline, and the number of ways to do this in 2026 is honestly overwhelming.&lt;/p&gt;

&lt;p&gt;Here's what I tried and what I learned.&lt;/p&gt;

&lt;h2&gt;Headless Chrome via Puppeteer&lt;/h2&gt;

&lt;p&gt;The classic. Spin up a headless browser, navigate, call &lt;code&gt;page.screenshot()&lt;/code&gt;. Works fine for simple pages.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;const browser = await puppeteer.launch({ headless: true });
const page = await browser.newPage();
await page.goto('https://example.com', { waitUntil: 'networkidle0' });
await page.screenshot({ path: 'shot.png', fullPage: true });
await browser.close();
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The problems start when you need scale. Each browser instance eats ~200-400MB RAM. Cookie banners, chat widgets, lazy-loaded content — you end up writing more workaround code than actual logic. And don't get me started on managing Chrome versions in CI.&lt;/p&gt;

&lt;h2&gt;Playwright (the Puppeteer successor, kinda)&lt;/h2&gt;

&lt;p&gt;Same idea, better API. Cross-browser support is nice if you actually need it (most people dont). The &lt;code&gt;waitForSelector&lt;/code&gt; and network interception stuff is cleaner.&lt;/p&gt;

&lt;p&gt;But the resource problem is identical. You're still running a full browser. Had a situation where our GitHub Actions runner kept OOM-killing during parallel captures.&lt;/p&gt;

&lt;h2&gt;html2canvas / dom-to-image&lt;/h2&gt;

&lt;p&gt;Client-side rendering. No actual browser engine — it re-renders the DOM to canvas. Fast, lightweight, zero infrastructure.&lt;/p&gt;

&lt;p&gt;Catch: it doesn't handle everything. CSS grid gaps, some transforms, web fonts that haven't loaded yet. If your pages are simple it works great. For anything production-grade with complex layouts, the output is... approximated.&lt;/p&gt;

&lt;h2&gt;Screenshot API&lt;/h2&gt;

&lt;p&gt;This is where I ended up. Offload the rendering to a service that maintains the browser infrastructure. Send a URL, get back an image.&lt;/p&gt;

&lt;p&gt;We went with &lt;a href="https://screenshotrun.com" rel="noopener noreferrer"&gt;ScreenshotRun&lt;/a&gt; — the API handles full-page capture, blocks cookie banners and ads, supports dark mode, retina, device emulation. One HTTP call replaces about 40 lines of Puppeteer boilerplate.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;curl 'https://api.screenshotrun.com/capture' \\
  -d url=https://example.com \\
  -d full_page=true \\
  -d block_cookies=true \\
  -d format=webp
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The tradeoff is obvious — you're paying per screenshot instead of paying for compute. For our volume (~2000 captures/month) it was cheaper than maintaining the infra ourselves.&lt;/p&gt;

&lt;h2&gt;Which one to pick&lt;/h2&gt;

&lt;p&gt;Depends on your situation tbh:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&amp;lt; 50 screenshots/month, simple pages&lt;/strong&gt; — Puppeteer/Playwright, run it locally&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Client-side only, no server&lt;/strong&gt; — html2canvas, accept the rendering gaps&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Production pipeline, need reliability&lt;/strong&gt; — API service, skip the infra headache&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Massive volume, custom needs&lt;/strong&gt; — self-hosted Playwright cluster, budget for DevOps time&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The rendering engine matters less than people think. What kills most screenshot setups is the edge cases: pages that need auth, SPAs that take 8 seconds to hydrate, cookie consent dialogs covering half the viewport. Whatever approach you pick, budget time for those.&lt;/p&gt;

&lt;p&gt;What's your setup for automated screenshots? Curious if anyone's running something completely different.&lt;/p&gt;

</description>
      <category>screenshotapi</category>
      <category>webcapture</category>
      <category>developertools</category>
      <category>api</category>
    </item>
    <item>
      <title>I Stopped Running Headless Chrome in CI and Just Use an API Now</title>
      <dc:creator>Vitalii Holben</dc:creator>
      <pubDate>Fri, 20 Nov 2026 01:02:10 +0000</pubDate>
      <link>https://dev.to/webmox/i-stopped-running-headless-chrome-in-ci-and-just-use-an-api-now-2h79</link>
      <guid>https://dev.to/webmox/i-stopped-running-headless-chrome-in-ci-and-just-use-an-api-now-2h79</guid>
      <description>


&lt;h2&gt;tags: webdev, testing, cicd, screenshots&lt;/h2&gt;

&lt;p&gt;Had a pretty standard setup: Puppeteer in a Docker container, running inside GitHub Actions, taking screenshots for visual regression tests. It worked. Mostly.&lt;/p&gt;

&lt;p&gt;The problems were always the same:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Chrome would randomly crash on larger pages, especially SPAs with heavy JS&lt;/li&gt;
&lt;li&gt;Memory usage was unpredictable. Some runs needed 2GB, others 512MB&lt;/li&gt;
&lt;li&gt;Font rendering differed between local and CI because of missing system fonts&lt;/li&gt;
&lt;li&gt;The Docker image was 1.2GB and took 45 seconds just to pull&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I spent way too long tweaking launch flags. `--disable-dev-shm-usage`, `--no-sandbox`, custom viewport hacks. Every few weeks something else would break.&lt;/p&gt;

&lt;h2&gt;What I switched to&lt;/h2&gt;

&lt;p&gt;Moved the screenshot step to an API call. One HTTP request, get back a PNG or WebP. The rendering happens on someone else's infrastructure with consistent fonts and consistent Chrome versions.&lt;/p&gt;

&lt;p&gt;

```javascript
const response = await fetch('https://screenshotrun.com/api/screenshot', {
method: 'POST',
headers: { 'Authorization': 'Bearer YOUR_KEY' },
body: JSON.stringify({
url: 'https://myapp.com/dashboard',
viewport: { width: 1280, height: 720 },
format: 'webp',
wait_for: '.dashboard-loaded'
})
});
const screenshot = await response.buffer();
```

&lt;/p&gt;

&lt;p&gt;That `wait_for` selector was the thing that actually convinced me. My old Puppeteer setup used `waitForTimeout(3000)` which was both too long and not long enough depending on the page. The selector-based wait means it captures after the content is actually there.&lt;/p&gt;

&lt;h2&gt;What changed&lt;/h2&gt;

&lt;p&gt;CI runs dropped from ~4 minutes to under 90 seconds for the screenshot step. No more Docker image maintenance. No more debugging Chrome crashes in CI logs at 11pm.&lt;/p&gt;

&lt;p&gt;The tradeoff is obvious — you're paying for API calls instead of compute time. For my use case (~200 screenshots per deploy, maybe 3 deploys a day) it costs less than the extra CI minutes did. Your math might be different if you're doing thousands.&lt;/p&gt;

&lt;p&gt;One thing I didnt expect: the screenshots are more consistent now. Same Chrome version, same fonts, same rendering every time. Made the visual diff comparison actually useful instead of flagging phantom differences from font smoothing.&lt;/p&gt;

&lt;p&gt;still keep Puppeteer locally for quick debugging. but for CI? not going back&lt;/p&gt;

</description>
      <category>screenshotapi</category>
      <category>webcapture</category>
      <category>developertools</category>
      <category>api</category>
    </item>
    <item>
      <title>I Built a Script to Diff Website Screenshots and Found Bugs I Missed for Months</title>
      <dc:creator>Vitalii Holben</dc:creator>
      <pubDate>Tue, 17 Nov 2026 16:40:20 +0000</pubDate>
      <link>https://dev.to/webmox/i-built-a-script-to-diff-website-screenshots-and-found-bugs-i-missed-for-months-3d6k</link>
      <guid>https://dev.to/webmox/i-built-a-script-to-diff-website-screenshots-and-found-bugs-i-missed-for-months-3d6k</guid>
      <description>&lt;p&gt;So I had this problem. We deploy to production pretty frequently -- sometimes twice a day -- and every once in a while something visual breaks. A button moves, a font changes, some CSS gets overridden by a new component. The kind of stuff that doesnt show up in unit tests.&lt;/p&gt;

&lt;p&gt;For a while I was just... manually checking pages after deploys. Open the site, click around, squint at things. You know how that goes. Sometimes I'd catch issues, most of the time I convinced myself everything looked fine.&lt;/p&gt;

&lt;p&gt;Then one day a client sent a screenshot of our pricing page where the CTA button had disappeared. It had been gone for 4 days. Four days. Nobody on the team noticed.&lt;/p&gt;

&lt;h2&gt;
  
  
  The pixel diff approach
&lt;/h2&gt;

&lt;p&gt;I wrote a quick script that takes screenshots of key pages and compares them pixel-by-pixel against a baseline. Nothing fancy -- headless Chrome, save PNGs, compare with pixelmatch. If the diff exceeds a threshold, flag it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;pixelmatch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"pixelmatch"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="no"&gt;PNG&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"pngjs"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;fs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"fs"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;img1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;PNG&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sync&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;readFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"baseline.png"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;img2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;PNG&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sync&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;readFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"current.png"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;diff&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="no"&gt;PNG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;img1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;img1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;numDiffPixels&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;pixelmatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;img1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;img2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;img1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;img1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;threshold&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.1&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Changed pixels: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;numDiffPixels&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Simple enough. But the first run was a disaster -- every page flagged because of dynamic content. Timestamps, user avatars, ad slots, cookie banners. The noise was unbearable.&lt;/p&gt;

&lt;h2&gt;
  
  
  What actually worked
&lt;/h2&gt;

&lt;p&gt;Had to get smarter about it. Added masking for dynamic regions, ran comparisons only on specific viewport sizes, and set different thresholds per page. The checkout page gets a tight threshold (even small shifts matter there), blog pages get a looser one.&lt;/p&gt;

&lt;p&gt;The biggest win was scheduling it to run after every deploy and dumping results into Slack. No more manual checking. If something breaks visually, I know within minutes.&lt;/p&gt;

&lt;p&gt;Couple things I learned the hard way:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Fonts load differently between runs&lt;/strong&gt; sometimes. Had to add a wait-for-fonts step or I'd get false positives from text rendering slightly differently.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Responsive breakpoints matter&lt;/strong&gt;. A bug at 768px width might not show at 1440px. I capture both now.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dark mode doubles your work&lt;/strong&gt;. If you support it, you gotta screenshot both themes. I... didn't at first. Guess where the bugs were hiding.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The annoying parts
&lt;/h2&gt;

&lt;p&gt;Maintaining baselines is tedious. Every intentional design change means updating screenshots. I tried automating that too -- if the PR is merged and approved, auto-update baselines -- but it still requires someone to eyeball the diff first.&lt;/p&gt;

&lt;p&gt;Also storage. Full-page screenshots at 2x resolution add up fast. Had to set up rotation to keep only the last 30 days.&lt;/p&gt;

&lt;p&gt;Its not perfect but its caught probably a dozen visual regressions that would have otherwise shipped to users. The setup took a weekend. Honestly should have done it way sooner.&lt;/p&gt;

&lt;p&gt;Anyone else doing visual regression testing? Curious what tools or approaches work for you.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>testing</category>
      <category>qa</category>
      <category>automation</category>
    </item>
    <item>
      <title>I Caught a Pricing Page Change That Would Have Cost Us a Client</title>
      <dc:creator>Vitalii Holben</dc:creator>
      <pubDate>Mon, 16 Nov 2026 11:43:39 +0000</pubDate>
      <link>https://dev.to/webmox/i-caught-a-pricing-page-change-that-would-have-cost-us-a-client-57mc</link>
      <guid>https://dev.to/webmox/i-caught-a-pricing-page-change-that-would-have-cost-us-a-client-57mc</guid>
      <description>&lt;p&gt;Last quarter, one of our SaaS vendors changed their API pricing tier without sending any notification. Not a blog post, not an email, nothing. The pricing page just... updated.&lt;/p&gt;

&lt;p&gt;We found out because we'd been taking weekly snapshots of our vendor pricing pages. Yes, I know that sounds paranoid. But after getting burned twice by unexpected price hikes, I started archiving the pages we depend on.&lt;/p&gt;

&lt;h2&gt;What happened&lt;/h2&gt;

&lt;p&gt;The vendor moved our usage tier from $99/month to $149/month. The change was subtle — they restructured the tiers so our request volume fell into a higher bracket. If you weren't comparing side by side, you might not even notice.&lt;/p&gt;

&lt;p&gt;We caught it within a week. Had a conversation with the vendor, negotiated to stay on the old pricing for 6 months while we evaluated alternatives.&lt;/p&gt;

&lt;h2&gt;Why this matters more than you think&lt;/h2&gt;

&lt;p&gt;SaaS pricing changes are more common than most people realize. Companies A/B test their pricing pages constantly. What you see today might not be what you see next month.&lt;/p&gt;

&lt;p&gt;If you're committing to a vendor based on their current pricing, you probably want a record of what that pricing actually was when you signed up.&lt;/p&gt;

&lt;h2&gt;My setup&lt;/h2&gt;

&lt;p&gt;Nothing fancy. A script that captures full-page screenshots of about 15 vendor pages once a week. Stored with timestamps. When a page looks different from the previous capture, I review it.&lt;/p&gt;

&lt;p&gt;Total effort: maybe 10 minutes a week to review the diffs. The vendor pricing catch alone saved us roughly $600/year, and more importantly, gave us leverage in the negotiation.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Not every monitoring story is about uptime. Sometimes it's about catching the changes that happen right on the surface, in plain sight.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>websitemonitoring</category>
      <category>screenshot</category>
      <category>archive</category>
      <category>changedetection</category>
    </item>
    <item>
      <title>I replaced Selenium screenshots with a 3-line API call</title>
      <dc:creator>Vitalii Holben</dc:creator>
      <pubDate>Fri, 16 Oct 2026 14:01:41 +0000</pubDate>
      <link>https://dev.to/webmox/i-replaced-selenium-screenshots-with-a-3-line-api-call-53fm</link>
      <guid>https://dev.to/webmox/i-replaced-selenium-screenshots-with-a-3-line-api-call-53fm</guid>
      <description>&lt;p&gt;Had a Selenium setup for taking screenshots in our CI pipeline. It worked, but maintaining it was a whole thing.&lt;/p&gt;
&lt;p&gt;The Docker image was 800MB because it bundled Chromium. Build times were 4 minutes just for the screenshot step. And every few weeks something broke -- ChromeDriver version mismatch, a new Chrome flag that changed default behavior, font rendering differences between CI runners.&lt;/p&gt;
&lt;p&gt;Spent more time babysitting the screenshot infrastructure than actually using the screenshots.&lt;/p&gt;
&lt;h2&gt;The switch&lt;/h2&gt;
&lt;p&gt;Ripped out the entire Selenium setup and replaced it with an HTTP call:&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;resp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="s2"&gt;`https://api.screenshotrun.com/capture?url=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nf"&gt;encodeURIComponent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;targetUrl&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;&amp;amp;width=1440&amp;amp;format=png`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Authorization&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`Bearer &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;API_KEY&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;buffer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;resp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;arrayBuffer&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;writeFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;screenshot.png&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Buffer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;buffer&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thats it. No browser binary, no driver compatibility matrix, no 800MB Docker layer.&lt;/p&gt;
&lt;h2&gt;What changed&lt;/h2&gt;
&lt;p&gt;Build times dropped from 4 minutes to about 12 seconds for the screenshot step. The Docker image went from 800MB to 120MB. Zero maintenance on the rendering side -- thats someone elses problem now.&lt;/p&gt;
&lt;p&gt;The screenshots are also more consistent. Same rendering environment every time, regardless of which CI runner picks up the job. No more "works on runner A, looks different on runner B" debugging sessions.&lt;/p&gt;
&lt;h2&gt;Tradeoffs&lt;/h2&gt;
&lt;p&gt;Costs money, obviously. For our volume (maybe 200 captures per day across staging and PR previews) its a few bucks a month. Way less than the engineer-hours I was spending on Selenium maintenance.&lt;/p&gt;
&lt;p&gt;You also depend on an external service. If their API is down during your CI run, your build fails. Added a simple retry with 3 attempts and a 5-second backoff. Hasnt been an issue in practice but its worth knowing about.&lt;/p&gt;
&lt;p&gt;If youre doing fewer than 50 screenshots a day and your Selenium setup is stable, probably not worth switching. But if youre fighting Chrome version mismatches every sprint like I was -- yeah, just use an API.&lt;/p&gt;

</description>
      <category>screenshotapi</category>
      <category>webcapture</category>
      <category>developertools</category>
      <category>api</category>
    </item>
    <item>
      <title>I Caught a Production CSS Bug Before Users Did</title>
      <dc:creator>Vitalii Holben</dc:creator>
      <pubDate>Fri, 02 Oct 2026 13:20:34 +0000</pubDate>
      <link>https://dev.to/webmox/i-caught-a-production-css-bug-before-users-did-3lb4</link>
      <guid>https://dev.to/webmox/i-caught-a-production-css-bug-before-users-did-3lb4</guid>
      <description>


&lt;h2&gt;title: I Caught a Production CSS Bug Before Users Did — Here's the Visual Regression Setup
published: true
tags: testing, webdev, css, devops&lt;/h2&gt;

&lt;p&gt;We shipped a "minor" font-size change last month. Updated the base size from 16px to 15px in our design tokens. Seemed harmless — the designer wanted tighter spacing.&lt;/p&gt;

&lt;p&gt;It broke the checkout flow.&lt;/p&gt;

&lt;p&gt;The payment form had a hardcoded min-height based on content size. With the smaller font, the content shifted up, and the submit button overlapped the terms checkbox on mobile viewports. Users on iPhone SE literally couldn't complete a purchase.&lt;/p&gt;

&lt;p&gt;We didn't catch it in code review because the CSS diff looked fine. We didn't catch it in unit tests because we don't render real layouts in Jest. We caught it 4 hours after deploy when support tickets started coming in.&lt;/p&gt;

&lt;h2&gt;What visual regression testing actually looks like&lt;/h2&gt;

&lt;p&gt;The concept: screenshot key pages before deploy, screenshot them after, diff the images. If pixels changed where they shouldn't have, block the deploy.&lt;/p&gt;

&lt;p&gt;In practice it's messier than that.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;# pseudo pipeline
1. Take "baseline" screenshots of production
2. Deploy to staging
3. Take "candidate" screenshots of staging
4. Compare each pair, flag differences above threshold
5. Human reviews flagged diffs
6. Approve or reject deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Step 4 is where most tools fall apart. Pixel-perfect comparison produces way too many false positives — browser antialiasing, font rendering differences, dynamic content like timestamps, ads, user avatars.&lt;/p&gt;

&lt;h2&gt;What I actually use&lt;/h2&gt;

&lt;p&gt;After trying a few setups (BackstopJS, Percy, custom Puppeteer scripts), I landed on a simpler approach:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Monitor key pages periodically with &lt;a href="https://snapshotarchive.com" rel="noopener noreferrer"&gt;SnapshotArchive&lt;/a&gt; — it takes scheduled screenshots and stores the history&lt;/li&gt;
&lt;li&gt;When we deploy, I compare the latest pre-deploy screenshot against the staging version&lt;/li&gt;
&lt;li&gt;Significant visual changes get flagged in Slack&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The advantage over CI-integrated tools: I get visual monitoring even when there's NO deploy. So if a third-party script changes, or a CDN serves different assets, or a CMS editor modifies content — I still see it.&lt;/p&gt;

&lt;h2&gt;The false positive problem&lt;/h2&gt;

&lt;p&gt;Every visual testing tool struggles with this. Here's what reduced noise for me:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mask dynamic regions&lt;/strong&gt; — hide elements that change on every load (timestamps, personalized content, ads). Most tools support CSS selectors for this.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Perceptual diffing over pixel diffing&lt;/strong&gt; — a 1px antialiasing difference isn't a real change. Tools that use perceptual comparison (SSIM or similar) produce way fewer false alarms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Separate critical from cosmetic&lt;/strong&gt; — the checkout page gets a 0.1% threshold. The blog page gets 5%. Not everything needs the same sensitivity.&lt;/p&gt;

&lt;h2&gt;My current setup in numbers&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;12 pages monitored&lt;/strong&gt; (homepage, pricing, checkout flow, key landing pages)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Screenshots every 6 hours&lt;/strong&gt; outside of deploys&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;~2 real alerts per week&lt;/strong&gt; after tuning thresholds&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;0 CSS incidents reaching production&lt;/strong&gt; since setting this up&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The checkout font-size bug would've shown up as a visual diff on staging before we merged. Instead it cost us 4 hours of lost conversions and a hotfix.&lt;/p&gt;

&lt;p&gt;The irony: the monitoring setup took an afternoon. The incident cost way more.&lt;/p&gt;

&lt;p&gt;What's your visual testing setup look like? Or are you still yolo-deploying CSS changes like we used to?&lt;/p&gt;

</description>
      <category>websitemonitoring</category>
      <category>screenshot</category>
      <category>archive</category>
      <category>changedetection</category>
    </item>
    <item>
      <title>I Built a Screenshot Pipeline That Handles 10K URLs Daily</title>
      <dc:creator>Vitalii Holben</dc:creator>
      <pubDate>Fri, 02 Oct 2026 13:20:24 +0000</pubDate>
      <link>https://dev.to/webmox/i-built-a-screenshot-pipeline-that-handles-10k-urls-daily-5cbd</link>
      <guid>https://dev.to/webmox/i-built-a-screenshot-pipeline-that-handles-10k-urls-daily-5cbd</guid>
      <description>


&lt;h2&gt;title: I Built a Screenshot Pipeline That Handles 10K URLs Daily (Here's What Broke First)
published: true
tags: webdev, api, automation, javascript&lt;/h2&gt;

&lt;p&gt;Last quarter I needed to generate preview thumbnails for a link aggregation tool. The requirement seemed simple: given a URL, produce a 1200x630 screenshot. At first it was maybe 50 URLs a day. Then the product grew.&lt;/p&gt;

&lt;p&gt;At around 2,000 URLs per day things started falling apart.&lt;/p&gt;

&lt;h2&gt;The first bottleneck: memory&lt;/h2&gt;

&lt;p&gt;Each Puppeteer page instance uses somewhere between 50-150MB of RAM depending on the page complexity. Running 10 concurrent pages meant 1.5GB just for Chrome, plus Node overhead. Our 4GB server started swapping.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;// the naive approach that doesn't scale
const pages = urls.map(async (url) =&amp;gt; {
  const page = await browser.newPage();
  await page.goto(url, { waitUntil: 'networkidle0' });
  await page.screenshot({ path: `${hash(url)}.png` });
  await page.close();
});
await Promise.all(pages); // boom, 10K pages at once
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The fix was a simple semaphore — limit to 4 concurrent pages and queue the rest. But even with that, Chrome would occasionally leak memory and need a restart every ~500 screenshots.&lt;/p&gt;

&lt;h2&gt;The second bottleneck: timeouts&lt;/h2&gt;

&lt;p&gt;Some URLs just don't load. Or they load but never reach &lt;code&gt;networkidle0&lt;/code&gt; because of persistent WebSocket connections or infinite polling. I was losing 15-20% of my daily runs to timeout-related failures.&lt;/p&gt;

&lt;p&gt;What worked:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;await page.goto(url, {
  waitUntil: 'domcontentloaded', // not networkidle0
  timeout: 15000
});
// then wait for specific readiness signal
await page.waitForFunction(
  () =&amp;gt; document.readyState === 'complete',
  { timeout: 5000 }
).catch(() =&amp;gt; {}); // screenshot whatever we have
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Switching from &lt;code&gt;networkidle0&lt;/code&gt; to &lt;code&gt;domcontentloaded&lt;/code&gt; + a short secondary wait cut my failure rate from 18% to under 3%.&lt;/p&gt;

&lt;h2&gt;The third bottleneck: me&lt;/h2&gt;

&lt;p&gt;At some point I was spending more time maintaining the screenshot infrastructure than building the actual product. Chrome updates breaking things, memory leak debugging, managing the screenshot queue, handling retries, storage rotation...&lt;/p&gt;

&lt;p&gt;I switched the whole thing to &lt;a href="https://screenshotrun.com" rel="noopener noreferrer"&gt;ScreenshotRun&lt;/a&gt; — send a URL via API, get back an image. No browser management, no server scaling, no 3am Chrome crashes.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;// entire screenshot pipeline, after
const response = await fetch('https://api.screenshotrun.com/capture', {
  method: 'POST',
  headers: { 'Authorization': `Bearer ${API_KEY}` },
  body: JSON.stringify({ url, width: 1200, height: 630 })
});
const image = await response.buffer();
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;My screenshot server went from a dedicated 8GB instance to zero infrastructure. The API handles the browser pool, the timeouts, the retries, the scaling.&lt;/p&gt;

&lt;h2&gt;What I'd do differently&lt;/h2&gt;

&lt;p&gt;If I was starting over and knew I'd hit scale:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Don't self-host screenshots past ~500/day&lt;/strong&gt; — the operational overhead isn't worth it unless you need very specific browser customization&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Always use &lt;code&gt;domcontentloaded&lt;/code&gt; over &lt;code&gt;networkidle0&lt;/code&gt;&lt;/strong&gt; — the few pages that need network idle aren't worth the timeout penalty on everything else&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Store WebP, not PNG&lt;/strong&gt; — 60-70% smaller files, virtually identical quality for thumbnails&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Build the retry logic from day one&lt;/strong&gt; — transient failures are guaranteed at scale, not edge cases&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Has anyone else hit similar scaling issues with browser-based tools? Curious what concurrency limits others settled on.&lt;/p&gt;

</description>
      <category>screenshotapi</category>
      <category>webcapture</category>
      <category>developertools</category>
      <category>api</category>
    </item>
    <item>
      <title>How to Capture Full-Page Screenshots of Infinite Scroll Pages</title>
      <dc:creator>Vitalii Holben</dc:creator>
      <pubDate>Wed, 23 Sep 2026 09:04:07 +0000</pubDate>
      <link>https://dev.to/webmox/how-to-capture-full-page-screenshots-of-infinite-scroll-pages-33gk</link>
      <guid>https://dev.to/webmox/how-to-capture-full-page-screenshots-of-infinite-scroll-pages-33gk</guid>
      <description>


&lt;h2&gt;title: How to Capture Full-Page Screenshots of Infinite Scroll Pages
tags: webdev, javascript, puppeteer, testing&lt;/h2&gt;

&lt;p&gt;Infinite scroll pages don't have a "bottom." That makes full-page screenshots tricky — the browser doesn't know how tall the page actually is until you've scrolled through everything.&lt;/p&gt;

&lt;p&gt;Here's how I handle it, and where the common approaches break.&lt;/p&gt;

&lt;h2&gt;The Naive Approach (and Why It Fails)&lt;/h2&gt;

&lt;p&gt;Puppeteer's &lt;code&gt;fullPage: true&lt;/code&gt; option works by measuring &lt;code&gt;document.body.scrollHeight&lt;/code&gt; and setting the viewport to that height before capturing. On a normal page, this is fine.&lt;/p&gt;

&lt;p&gt;On an infinite scroll page, &lt;code&gt;scrollHeight&lt;/code&gt; only reflects content that's already loaded. If the page lazy-loads 50 more items when you reach the bottom... those items aren't in the DOM yet when the screenshot fires.&lt;/p&gt;

&lt;p&gt;You get a screenshot of the first batch of content and nothing else.&lt;/p&gt;

&lt;h2&gt;Scroll, Wait, Repeat&lt;/h2&gt;

&lt;p&gt;The workaround is manual scrolling:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;async function scrollToBottom(page) {
  let previousHeight = 0;
  let currentHeight = await page.evaluate(() =&amp;gt; document.body.scrollHeight);
  
  while (previousHeight !== currentHeight) {
    previousHeight = currentHeight;
    await page.evaluate(() =&amp;gt; window.scrollTo(0, document.body.scrollHeight));
    await page.waitForTimeout(1500);
    currentHeight = await page.evaluate(() =&amp;gt; document.body.scrollHeight);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Scroll to bottom, wait for new content, check if height changed. When it stops changing, you've hit the end. Then take your &lt;code&gt;fullPage&lt;/code&gt; screenshot.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;waitForTimeout(1500)&lt;/code&gt; is a guess. Some pages load fast, some make API calls that take 3+ seconds. I've seen people use &lt;code&gt;waitForNetworkIdle&lt;/code&gt; here, but that can hang forever on pages with analytics pings and websocket connections.&lt;/p&gt;

&lt;p&gt;What I do: wait for timeout, then also check if new DOM elements appeared:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;const itemCount = await page.evaluate(
  () =&amp;gt; document.querySelectorAll('.feed-item').length
);
// scroll...
const newCount = await page.evaluate(
  () =&amp;gt; document.querySelectorAll('.feed-item').length
);
if (newCount === itemCount) break;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;More reliable than height checks for some layouts.&lt;/p&gt;

&lt;h2&gt;The Memory Problem&lt;/h2&gt;

&lt;p&gt;A page with 500 loaded items is big. Setting the viewport to 1920x50000 and capturing as PNG creates a massive image. Chrome might crash, or your server runs out of memory.&lt;/p&gt;

&lt;p&gt;Two options:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cap the scroll depth.&lt;/strong&gt; Don't try to capture everything. Scroll N times and stop:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;const MAX_SCROLLS = 20;
for (let i = 0; i &amp;lt; MAX_SCROLLS; i++) {
  await page.evaluate(() =&amp;gt; window.scrollTo(0, document.body.scrollHeight));
  await page.waitForTimeout(1000);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Use JPEG instead of PNG.&lt;/strong&gt; For long screenshots, JPEG at quality 80 is usually 5-10x smaller:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;await page.screenshot({ 
  fullPage: true, 
  type: 'jpeg', 
  quality: 80 
});
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;Intersection Observer Gotchas&lt;/h2&gt;

&lt;p&gt;Modern sites use IntersectionObserver for lazy loading. The observer fires when elements enter the viewport. In headless Chrome, scrolling programmatically does trigger these observers — but only if you actually scroll through the viewport, not just jump to the bottom.&lt;/p&gt;

&lt;p&gt;If you &lt;code&gt;window.scrollTo(0, 99999)&lt;/code&gt; in one jump, observers for elements in the middle of the page might not fire. Scroll incrementally:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;const scrollStep = 500;
let scrollPos = 0;
const maxHeight = await page.evaluate(() =&amp;gt; document.body.scrollHeight);

while (scrollPos &amp;lt; maxHeight) {
  scrollPos += scrollStep;
  await page.evaluate((y) =&amp;gt; window.scrollTo(0, y), scrollPos);
  await page.waitForTimeout(200);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Slower but catches all the lazy-loaded content.&lt;/p&gt;

&lt;h2&gt;When to Give Up&lt;/h2&gt;

&lt;p&gt;Some pages are genuinely infinite — social media feeds, search results that go on forever. Set a reasonable limit — either by scroll count, total height, or time spent — and document it. "We capture the first 50 items" is a perfectly valid approach.&lt;/p&gt;

</description>
      <category>screenshotapi</category>
      <category>webcapture</category>
      <category>developertools</category>
      <category>api</category>
    </item>
    <item>
      <title>How to Capture Dark Mode Screenshots Programmatically</title>
      <dc:creator>Vitalii Holben</dc:creator>
      <pubDate>Wed, 16 Sep 2026 12:23:17 +0000</pubDate>
      <link>https://dev.to/webmox/how-to-capture-dark-mode-screenshots-programmatically-2d02</link>
      <guid>https://dev.to/webmox/how-to-capture-dark-mode-screenshots-programmatically-2d02</guid>
      <description>&lt;p&gt;Needed to generate both light and dark mode screenshots of a marketing site for a client's brand guidelines doc. Turns out forcing dark mode in a headless browser isn't as straightforward as setting a CSS class.&lt;/p&gt;

&lt;p&gt;Here's how I got it working with Playwright (same approach works with Puppeteer).&lt;/p&gt;

&lt;h2&gt;
  
  
  The prefers-color-scheme approach
&lt;/h2&gt;

&lt;p&gt;Most modern sites use the &lt;code&gt;prefers-color-scheme&lt;/code&gt; media query for dark mode. You can emulate this in Playwright:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;chromium&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;playwright&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;browser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;chromium&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;launch&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="c1"&gt;// Light mode capture&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;lightCtx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;browser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;newContext&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;colorScheme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;light&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;viewport&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1280&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;800&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;lightPage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;lightCtx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;newPage&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;lightPage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;goto&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://example.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;lightPage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;screenshot&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;light.png&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;fullPage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="c1"&gt;// Dark mode capture&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;darkCtx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;browser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;newContext&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;colorScheme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dark&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;viewport&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1280&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;800&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;darkPage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;darkCtx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;newPage&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;darkPage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;goto&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://example.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;darkPage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;screenshot&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dark.png&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;fullPage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;browser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;})();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The key is &lt;code&gt;colorScheme: 'dark'&lt;/code&gt; in the browser context. This sets &lt;code&gt;prefers-color-scheme: dark&lt;/code&gt; at the OS level, so the page responds exactly as it would on a user's machine with dark mode enabled.&lt;/p&gt;

&lt;h2&gt;
  
  
  When the site uses a toggle instead
&lt;/h2&gt;

&lt;p&gt;Some sites don't rely on the media query. They use a JavaScript toggle that sets a class on &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; or &lt;code&gt;&amp;lt;html&amp;gt;&lt;/code&gt; — something like &lt;code&gt;class="dark"&lt;/code&gt; or &lt;code&gt;data-theme="dark"&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For these, you need to interact with the page:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;browser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;newPage&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;goto&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://example.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Take light mode screenshot first&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;screenshot&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;light.png&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// Click the theme toggle&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;click&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[data-testid="theme-toggle"]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Wait for transition animations to finish&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;waitForTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;screenshot&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dark.png&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you don't know the toggle's selector, you can force it by injecting the class directly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;evaluate&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;documentElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;classList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dark&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="c1"&gt;// or&lt;/span&gt;
  &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;documentElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;data-theme&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dark&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// Give CSS transitions time to complete&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;waitForTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;screenshot&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dark-forced.png&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is hacky but reliable when you can't find the toggle button.&lt;/p&gt;

&lt;h2&gt;
  
  
  Handling both approaches at once
&lt;/h2&gt;

&lt;p&gt;Real-world sites sometimes use a combination — media query as default, with a manual override stored in localStorage. Here's what I ended up with for a batch capture script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;captureWithTheme&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;outputPath&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;browser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;newContext&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;colorScheme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;viewport&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1280&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;800&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;newPage&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;goto&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;waitUntil&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;networkidle&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="c1"&gt;// Also set common localStorage/cookie theme preferences&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;evaluate&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;theme&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;color-mode&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cookie&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`theme=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;; path=/`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Reload to pick up localStorage-based themes&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reload&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;waitUntil&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;networkidle&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="c1"&gt;// Force the class as a fallback&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;evaluate&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;documentElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;classList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;remove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;light&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dark&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;documentElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;classList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;documentElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;data-theme&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;waitForTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;screenshot&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;outputPath&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;fullPage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Usage&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;captureWithTheme&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://example.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dark&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dark.png&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;captureWithTheme&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://example.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;light&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;light.png&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bit aggressive with the overrides, but it catches most theme implementations I've encountered.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Puppeteer equivalent
&lt;/h2&gt;

&lt;p&gt;If you're using Puppeteer instead of Playwright, the media query emulation looks different:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;browser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;newPage&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Emulate dark mode&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;emulateMediaFeatures&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;prefers-color-scheme&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dark&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;]);&lt;/span&gt;

&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;goto&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://example.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;screenshot&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dark.png&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;emulateMediaFeatures&lt;/code&gt; works well but you need to call it before navigating to the page. If you call it after, some components might not re-render until you force a repaint.&lt;/p&gt;

&lt;h2&gt;
  
  
  Gotchas I ran into
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;CSS transitions mess up screenshots.&lt;/strong&gt; If the site has a smooth dark-to-light transition (0.3s fade), your screenshot might catch it mid-transition. Either wait for the animation to complete or disable transitions entirely:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addStyleTag&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;*, *::before, *::after { transition: none !important; animation: none !important; }&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Images don't always switch.&lt;/strong&gt; Some sites serve different image assets for light/dark mode using the &lt;code&gt;&amp;lt;picture&amp;gt;&lt;/code&gt; element with &lt;code&gt;prefers-color-scheme&lt;/code&gt; in the &lt;code&gt;&amp;lt;source&amp;gt;&lt;/code&gt; media attribute. The &lt;code&gt;colorScheme&lt;/code&gt; context option handles this correctly. The JavaScript class-forcing approach does not — you'll get light mode images with a dark background.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Third-party widgets ignore your theme.&lt;/strong&gt; Embedded chat widgets, analytics consent banners, and social embeds use their own theme logic. Your dark mode screenshot might have a blinding white cookie popup in the corner. Remove these elements before capturing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;evaluate&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;selectors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[class*="cookie"]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[class*="consent"]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                     &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[class*="chat-widget"]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;iframe[src*="chatbot"]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="nx"&gt;selectors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sel&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sel&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;remove&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;System dark mode affects more than colors.&lt;/strong&gt; On macOS, dark mode also changes scrollbar appearance, form control styling, and the default background color of transparent elements. If pixel-perfect consistency between light and dark captures matters, set a fixed background on &lt;code&gt;&amp;lt;html&amp;gt;&lt;/code&gt; before capturing.&lt;/p&gt;

&lt;h2&gt;
  
  
  When to use this
&lt;/h2&gt;

&lt;p&gt;Visual regression testing is the obvious case — you want to verify that both themes render correctly after every deploy. But I've also used it for generating marketing assets (light mode for print, dark mode for social media previews) and documentation screenshots where you want to show both variants side by side.&lt;/p&gt;

&lt;p&gt;The Playwright approach with &lt;code&gt;colorScheme&lt;/code&gt; in the browser context is the cleanest solution for media-query-based themes. For everything else, the JavaScript override approach gets the job done even if it feels a bit brute-force.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>testing</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How to Handle Anti-Bot Measures When Taking Screenshots Programmatically</title>
      <dc:creator>Vitalii Holben</dc:creator>
      <pubDate>Thu, 03 Sep 2026 12:33:16 +0000</pubDate>
      <link>https://dev.to/webmox/how-to-handle-anti-bot-measures-when-taking-screenshots-programmatically-1dc4</link>
      <guid>https://dev.to/webmox/how-to-handle-anti-bot-measures-when-taking-screenshots-programmatically-1dc4</guid>
      <description>&lt;p&gt;How to Handle Anti-Bot Measures When Taking Screenshots Programmatically&lt;/p&gt;

&lt;p&gt;You send a request. The page loads. The screenshot comes back blank, or shows a CAPTCHA, or captures a "Please verify you're human" wall. This is one of the most common problems when building any screenshot pipeline.&lt;/p&gt;

&lt;p&gt;Here's what's actually happening and how to deal with it.&lt;/p&gt;

&lt;h2&gt;Why headless browsers get flagged&lt;/h2&gt;

&lt;p&gt;Bot detection works by looking for patterns that differ from real users. Headless Chrome has several tells:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;navigator.webdriver&lt;/code&gt; returns &lt;code&gt;true&lt;/code&gt; by default&lt;/li&gt;
&lt;li&gt;Missing Chrome-specific properties like &lt;code&gt;window.chrome&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Inconsistent screen dimensions (no monitor attached means no GPU info)&lt;/li&gt;
&lt;li&gt;Mouse events fire at pixel-perfect coordinates with no jitter&lt;/li&gt;
&lt;li&gt;Font fingerprints differ from headed browsers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Modern detection services (Cloudflare, Akamai, Datadome) look for combinations of these signals, not individual flags. Spoofing one without the others often makes the fingerprint &lt;em&gt;more&lt;/em&gt; suspicious, not less.&lt;/p&gt;

&lt;h2&gt;The practical spectrum of detection&lt;/h2&gt;

&lt;p&gt;Most sites fall into one of three categories:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;No active detection&lt;/strong&gt; — a basic bot check via User-Agent string at most. Simple fix: set a realistic UA.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Passive fingerprinting&lt;/strong&gt; — loads a detection script, collects signals, blocks on second or third visit. You'll see this on news sites, e-commerce, media platforms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Active challenges&lt;/strong&gt; — Cloudflare Turnstile, hCaptcha, reCAPTCHA v3 score-based. These require real interaction or a solving service.&lt;/p&gt;

&lt;p&gt;Know which category your target falls into before spending time on it.&lt;/p&gt;

&lt;h2&gt;Fixes that work for most cases&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Use a stealth plugin&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For Playwright, &lt;code&gt;playwright-extra&lt;/code&gt; with &lt;code&gt;puppeteer-extra-plugin-stealth&lt;/code&gt; patches the most common fingerprinting vectors:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;npm install playwright-extra puppeteer-extra-plugin-stealth
&lt;/code&gt;&lt;/pre&gt;

&lt;pre&gt;&lt;code&gt;import { chromium } from 'playwright-extra';
import StealthPlugin from 'puppeteer-extra-plugin-stealth';

chromium.use(StealthPlugin());
const browser = await chromium.launch();
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This handles &lt;code&gt;navigator.webdriver&lt;/code&gt;, &lt;code&gt;window.chrome&lt;/code&gt;, and several other flags automatically.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Set realistic headers&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;await page.setExtraHTTPHeaders({
  'Accept-Language': 'en-US,en;q=0.9',
  'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
  'sec-ch-ua': '"Chromium";v="120", "Google Chrome";v="120"',
  'sec-ch-ua-mobile': '?0',
  'sec-ch-ua-platform': '"macOS"',
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;3. Use a real Chrome binary, not Chromium&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Chromium's font set differs from Chrome. Detection services track which fonts are available. Running headful Chrome via &lt;code&gt;executablePath&lt;/code&gt; gives you a more convincing fingerprint than the bundled Chromium.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Add realistic delays and mouse movement&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;// Move mouse before clicking
await page.mouse.move(100 + Math.random() * 50, 200 + Math.random() * 30);
await page.waitForTimeout(300 + Math.random() * 500);
await page.click('#target');
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Perfectly timed, pixel-precise interactions are a dead giveaway. Add jitter.&lt;/p&gt;

&lt;h2&gt;When the above isn't enough&lt;/h2&gt;

&lt;p&gt;Some sites run heavy fingerprinting that's hard to spoof at the browser level. Options at this point:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Residential proxies&lt;/strong&gt; — rotate real residential IPs. The IP reputation matters as much as the browser fingerprint. Datacenter IPs are often pre-blocked.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Browser profiles&lt;/strong&gt; — maintain persistent browser profiles with cookies, browsing history, and localStorage. A "fresh" headless browser looks different from a browser with 3 weeks of history.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Playwright with persistent context&lt;/strong&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;const context = await chromium.launchPersistentContext('./user-data-dir', {
  headless: false, // or true with stealth
});
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;The ethical and legal line&lt;/h2&gt;

&lt;p&gt;There's a difference between taking screenshots of public pages for archival, testing, or display purposes — which is generally fine — and bypassing authentication or rate limits to scrape data at scale. The former is what most screenshot tools do. The latter runs into Terms of Service issues and, in some jurisdictions, legal risk.&lt;/p&gt;

&lt;p&gt;Worth being clear on which side of that line your use case sits before investing in bypass techniques.&lt;/p&gt;

&lt;h2&gt;What to monitor&lt;/h2&gt;

&lt;p&gt;Once you have a working pipeline, track failure reasons explicitly:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;const response = await page.goto(url, { waitUntil: 'networkidle2' });
if (response.status() === 403 || response.status() === 429) {
  // Bot detection hit — log, rotate IP, back off
}

const pageTitle = await page.title();
if (pageTitle.toLowerCase().includes('captcha') || pageTitle.includes('verify')) {
  // Challenge page — flag for manual review
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Silent failures — a 200 status but a CAPTCHA screenshot — are harder to catch. Use a content hash comparison or check for expected elements before saving the screenshot.&lt;/p&gt;

&lt;p&gt;The problem doesn't go away entirely, but being systematic about detection and response turns a reliability nightmare into something manageable.&lt;/p&gt;

</description>
      <category>websitemonitoring</category>
      <category>screenshot</category>
      <category>archive</category>
      <category>changedetection</category>
    </item>
  </channel>
</rss>
