<?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: rokaskve</title>
    <description>The latest articles on DEV Community by rokaskve (@rokaskve).</description>
    <link>https://dev.to/rokaskve</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%2F4282567%2Fa00ea4c9-a6f1-49e5-b4a4-becc7e6994f2.jpg</url>
      <title>DEV Community: rokaskve</title>
      <link>https://dev.to/rokaskve</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rokaskve"/>
    <language>en</language>
    <item>
      <title>Screenshot APIs compared in 2026: Urlbox, ScreenshotOne, ApiFlash and friends.</title>
      <dc:creator>rokaskve</dc:creator>
      <pubDate>Fri, 04 Dec 2026 11:53:19 +0000</pubDate>
      <link>https://dev.to/rokaskve/screenshot-apis-compared-in-2026-urlbox-screenshotone-apiflash-and-friends-1g0f</link>
      <guid>https://dev.to/rokaskve/screenshot-apis-compared-in-2026-urlbox-screenshotone-apiflash-and-friends-1g0f</guid>
      <description>&lt;p&gt;If you're building anything that captures webpages — social preview generators, PDF invoices, competitor monitoring, automated design review — you'll want a screenshot API. There are roughly ten decent options on the market. This post narrows it to the five you'll actually consider in 2026, and compares them on the axes that matter: &lt;strong&gt;price per thousand captures&lt;/strong&gt;, &lt;strong&gt;feature completeness&lt;/strong&gt;, &lt;strong&gt;reliability&lt;/strong&gt;, and &lt;strong&gt;developer experience&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Disclosure: we make getSnap.dev, one of the five. We tried to be fair about the trade-offs — every comparison table below is grounded in the vendors' current public pricing pages and docs, checked on the date this post was published. Where getSnap.dev doesn't win, we say so.&lt;/p&gt;

&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cheapest for high volume:&lt;/strong&gt; getSnap.dev at $79/mo for 100,000 captures ($0.79/1K).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Widest feature surface:&lt;/strong&gt; Urlbox — oldest player, most templates, most integrations. Expensive.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Best free tier:&lt;/strong&gt; tied — ScreenshotOne, ScreenshotAPI, ApiFlash, and getSnap.dev all give 100 free/mo.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Best if you need scrolling video:&lt;/strong&gt; getSnap.dev, Urlbox, ScreenshotOne or ScreenshotAPI.net all record it. ScreenshotAPI.net allows the longest clips at 60 seconds; ApiFlash has no video at all.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Best if you need scheduled captures:&lt;/strong&gt; getSnap.dev or Urlbox again.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Best if all you need is a screenshot with no bells or whistles:&lt;/strong&gt; ApiFlash — simple GET-style API, no fluff.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Price per 1,000 captures
&lt;/h2&gt;

&lt;p&gt;Take the entry-level paid plan of each vendor, divide by monthly quota, get the price per thousand captures. This is the number you actually pay long-term once your app has any traction.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Vendor&lt;/th&gt;
&lt;th&gt;Entry plan&lt;/th&gt;
&lt;th&gt;Included&lt;/th&gt;
&lt;th&gt;$/1,000&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;getSnap.dev&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Starter $9/mo&lt;/td&gt;
&lt;td&gt;5,000&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;$1.80&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ApiFlash&lt;/td&gt;
&lt;td&gt;Lite $7/mo&lt;/td&gt;
&lt;td&gt;1,000&lt;/td&gt;
&lt;td&gt;$7.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ScreenshotOne&lt;/td&gt;
&lt;td&gt;Basic $17/mo&lt;/td&gt;
&lt;td&gt;2,000&lt;/td&gt;
&lt;td&gt;$8.50&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ScreenshotAPI.net&lt;/td&gt;
&lt;td&gt;Essential $9/mo&lt;/td&gt;
&lt;td&gt;1,000&lt;/td&gt;
&lt;td&gt;$9.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Urlbox&lt;/td&gt;
&lt;td&gt;Lo-Fi $19/mo&lt;/td&gt;
&lt;td&gt;2,000&lt;/td&gt;
&lt;td&gt;$9.50&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Plan names, prices and SDK availability checked against each vendor's own pricing page and public repositories on 25 October 2026, the same day the feature table below was re-checked against their current API docs. Plans change often; if these differ from what you see, theirs is the authority.&lt;/p&gt;

&lt;p&gt;Now the same at 100,000 captures/month — the point where you're a real customer:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Vendor&lt;/th&gt;
&lt;th&gt;Largest listed plan&lt;/th&gt;
&lt;th&gt;Included&lt;/th&gt;
&lt;th&gt;$/1,000&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;getSnap.dev&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Business $79/mo&lt;/td&gt;
&lt;td&gt;100,000&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;$0.79&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ApiFlash&lt;/td&gt;
&lt;td&gt;Large $180/mo&lt;/td&gt;
&lt;td&gt;100,000&lt;/td&gt;
&lt;td&gt;$1.80&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ScreenshotOne&lt;/td&gt;
&lt;td&gt;Scale $259/mo&lt;/td&gt;
&lt;td&gt;50,000&lt;/td&gt;
&lt;td&gt;$5.18&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Urlbox&lt;/td&gt;
&lt;td&gt;Business $495/mo base&lt;/td&gt;
&lt;td&gt;+ $3 per 1,000&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ScreenshotAPI.net&lt;/td&gt;
&lt;td&gt;Business $175/mo&lt;/td&gt;
&lt;td&gt;100,000&lt;/td&gt;
&lt;td&gt;$1.75&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Plan names, prices and SDK availability checked against each vendor's own pricing page and public repositories on 25 October 2026, the same day the feature table below was re-checked against their current API docs. Plans change often; if these differ from what you see, theirs is the authority.&lt;/p&gt;

&lt;p&gt;getSnap.dev's pricing is not a promotional trick — it's a lean-stack cost structure: Fastify + Playwright + Redis on a single droplet with DigitalOcean Spaces as the CDN, no VC funding to service, no sales team to pay. The savings pass to you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Feature completeness
&lt;/h2&gt;

&lt;p&gt;Every vendor supports the basics — PNG output, custom viewport, full page, mobile emulation, dark mode. What separates them is the long tail. Here's what actually varies:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;getSnap.dev&lt;/th&gt;
&lt;th&gt;Urlbox&lt;/th&gt;
&lt;th&gt;ScreenshotOne&lt;/th&gt;
&lt;th&gt;ScreenshotAPI&lt;/th&gt;
&lt;th&gt;ApiFlash&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;AVIF output&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Full-page slicing for AI vision&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Not documented&lt;/td&gt;
&lt;td&gt;Not documented&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PDF customisation (headers, page range, metadata)&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Partial&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Partial&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Page metadata extraction&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Scheduled captures (cron + webhook)&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Scrolling video (MP4/GIF)&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Proxy routing&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Batch capture in one request&lt;/td&gt;
&lt;td&gt;Yes (100)&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes (200)&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Node.js SDK&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Python SDK&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Plan names, prices and SDK availability checked against each vendor's own pricing page and public repositories on 25 October 2026, the same day the feature table below was re-checked against their current API docs. Plans change often; if these differ from what you see, theirs is the authority.&lt;/p&gt;

&lt;p&gt;A few things worth pointing out from that table:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://getsnap.dev/how-to-take-a-full-page-screenshot.html" rel="noopener noreferrer"&gt;Full-page slicing for AI vision&lt;/a&gt;.&lt;/strong&gt; Vision models cap at around 8,000 pixels of height, so a 15,000px full-page capture cannot be fed to one whole. getSnap.dev and ScreenshotOne both split tall captures into overlapping strips uploaded as separate objects — and, oddly, with the same parameter names (&lt;code&gt;full_page_slices&lt;/code&gt;, &lt;code&gt;full_page_slice_height&lt;/code&gt;, &lt;code&gt;full_page_slice_overlap_height&lt;/code&gt;). ScreenshotOne allows slices up to 16,000px; ours cap at 16,000 too. We are not aware of Urlbox, ApiFlash or ScreenshotAPI.net documenting an equivalent, but absence from their docs is not proof of absence.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://getsnap.dev/html-to-pdf-api.html" rel="noopener noreferrer"&gt;PDF customisation&lt;/a&gt;.&lt;/strong&gt; Everyone can make a PDF. The question is how much of it you can control: page size, a header with page numbers, a footer with the document title, filtering to pages 1–5, and author metadata. getSnap.dev supports all of those. Checked against each vendor’s current docs on 25 October 2026: Urlbox has page ranges and custom header/footer templates but no document metadata; ScreenshotAPI.net has page ranges only; ScreenshotOne has margins and paper size but neither page ranges nor headers; ApiFlash produces no PDF at all.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Batch capture.&lt;/strong&gt; A single request that hits 100 URLs and returns 100 CDN links. If you're building any kind of link-preview generator or bulk archival tool, this is the difference between one API call and 100.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scrolling video.&lt;/strong&gt; getSnap.dev, Urlbox, ScreenshotOne and ScreenshotAPI.net all record a scrolling pass as MP4 or GIF. ScreenshotOne also offers MOV, AVI and WebM; ScreenshotAPI.net allows up to 60 seconds against our 30. ApiFlash has no video. Useful for changelog demos, design-review mockups and marketing clips — and not a differentiator for us, whatever we said here previously.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Developer experience
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Rate limits + quotas
&lt;/h3&gt;

&lt;p&gt;Free tier on all five vendors is around 100 captures/month. Paid tiers vary in how they signal exhaustion:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;getSnap.dev:&lt;/strong&gt; HTTP 402 with a JSON body that includes &lt;code&gt;used&lt;/code&gt; and &lt;code&gt;limit&lt;/code&gt; integers. Response headers on every successful call include &lt;code&gt;X-Credits-Remaining&lt;/code&gt;, &lt;code&gt;X-RateLimit-Remaining&lt;/code&gt;, and &lt;code&gt;X-RateLimit-Reset&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Urlbox / ScreenshotOne:&lt;/strong&gt; HTTP 429 with retry semantics.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ApiFlash:&lt;/strong&gt; plaintext error page.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Cache semantics
&lt;/h3&gt;

&lt;p&gt;If you request the same screenshot twice, does the vendor charge you twice?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;getSnap.dev:&lt;/strong&gt; No. Cached responses (indicated by &lt;code&gt;X-Cache: HIT&lt;/code&gt;) don't consume quota. Cache is keyed by a hash of every option that would affect the output, so any change to viewport, format, or JS injection produces a fresh capture.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Urlbox:&lt;/strong&gt; Yes and no — renders are billed per request but they have a separate CDN caching layer.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ScreenshotOne / ScreenshotAPI / ApiFlash:&lt;/strong&gt; Every request charges. If you request the same page 100 times per day, that's 100 credits.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  SDKs
&lt;/h3&gt;

&lt;p&gt;Node.js and Python cover roughly 85% of the API-developer market. getSnap.dev, ScreenshotOne and Urlbox all ship both — Urlbox publishes &lt;code&gt;urlbox&lt;/code&gt; on PyPI as well as npm, which an earlier version of this page missed. ScreenshotAPI.net is Node-only, and ApiFlash leaves you to write your own HTTP wrapper.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Node.js&lt;/span&gt;
npm install getsnap

&lt;span class="c"&gt;# Python&lt;/span&gt;
pip install getsnap
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both SDKs stay type-safe against the full option surface (68+ parameters), and both are zero-config — you just pass your API key.&lt;/p&gt;

&lt;h2&gt;
  
  
  When each vendor is the right choice
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Use Urlbox if
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;You need pre-built templates for common designs (invoices, receipts, OG images) and don't want to build them yourself.&lt;/li&gt;
&lt;li&gt;You're already a large-scale customer on an enterprise contract with them.&lt;/li&gt;
&lt;li&gt;Vendor stability matters more than price. Urlbox has been around since 2015 and is the incumbent.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Use ScreenshotOne if
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;You're comfortable at their $29+ price point and want a solid Node + Python SDK combo.&lt;/li&gt;
&lt;li&gt;You need their specific integration with Zapier or n8n.&lt;/li&gt;
&lt;li&gt;Your capture volume sits in the sweet spot of 5–25K/month where their pricing is competitive.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Use ApiFlash if
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;You want the simplest possible GET-request API. &lt;code&gt;GET https://api.apiflash.com/v1/urltoimage?url=…&lt;/code&gt; — no JSON payload, no headers.&lt;/li&gt;
&lt;li&gt;You only need PNG output and don't care about PDF, video, or extraction.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Use ScreenshotAPI if
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Honestly, we're not sure. They're neither the cheapest nor the most feature-complete. If we're missing a killer feature they have, please &lt;a href="mailto:support@getsnap.dev"&gt;let us know&lt;/a&gt; and we'll update this post.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Use getSnap.dev if
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;You want the widest feature set at the lowest price. Depending on the provider and the volume we are 1.6–10× cheaper — widest against Urlbox and ScreenshotOne, narrowest against ApiFlash and ScreenshotAPI.net, who undercut us below about 1,000 a month.&lt;/li&gt;
&lt;li&gt;You need PDF output you can actually control — page ranges, custom headers and footers and document metadata together — or granular request blocking. Scheduled captures narrow the field to us and ScreenshotAPI.net; full-page slicing to us and ScreenshotOne.&lt;/li&gt;
&lt;li&gt;You want a batch endpoint (up to 100 URLs per call). ScreenshotOne and ScreenshotAPI.net have one too; Urlbox and ApiFlash do not.&lt;/li&gt;
&lt;li&gt;You want both Node.js and Python SDKs maintained by the same team.&lt;/li&gt;
&lt;li&gt;You want the docs to actually be current with the API. &lt;a href="https://getsnap.dev/docs/api-reference.html" rel="noopener noreferrer"&gt;See for yourself.&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Detailed head-to-head comparisons
&lt;/h2&gt;

&lt;p&gt;Each of these goes further than this roundup does — current pricing checked against the vendor's own page, a parameter-by-parameter migration guide, and an honest list of the cases where you should stay where you are.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://getsnap.dev/compare/urlbox.html" rel="noopener noreferrer"&gt;getSnap.dev vs Urlbox&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://getsnap.dev/compare/screenshotone.html" rel="noopener noreferrer"&gt;getSnap.dev vs ScreenshotOne&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://getsnap.dev/compare/apiflash.html" rel="noopener noreferrer"&gt;getSnap.dev vs ApiFlash&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://getsnap.dev/compare/screenshotapi.html" rel="noopener noreferrer"&gt;getSnap.dev vs ScreenshotAPI.net&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Still deciding whether to host a browser at all? These weigh the libraries against a hosted API, using measured costs from this deployment: &lt;a href="https://getsnap.dev/alternative-to/puppeteer.html" rel="noopener noreferrer"&gt;Puppeteer&lt;/a&gt;, &lt;a href="https://getsnap.dev/alternative-to/playwright.html" rel="noopener noreferrer"&gt;Playwright&lt;/a&gt;, &lt;a href="https://getsnap.dev/alternative-to/selenium.html" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt; and &lt;a href="https://getsnap.dev/alternative-to/html2canvas.html" rel="noopener noreferrer"&gt;html2canvas&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Working in a specific language? There are quick-start guides for &lt;a href="https://getsnap.dev/screenshot-api/python.html" rel="noopener noreferrer"&gt;Python&lt;/a&gt;, &lt;a href="https://getsnap.dev/screenshot-api/nodejs.html" rel="noopener noreferrer"&gt;Node.js&lt;/a&gt;, &lt;a href="https://getsnap.dev/screenshot-api/php.html" rel="noopener noreferrer"&gt;PHP&lt;/a&gt;, &lt;a href="https://getsnap.dev/screenshot-api/ruby.html" rel="noopener noreferrer"&gt;Ruby&lt;/a&gt;, &lt;a href="https://getsnap.dev/screenshot-api/go.html" rel="noopener noreferrer"&gt;Go&lt;/a&gt;, &lt;a href="https://getsnap.dev/screenshot-api/java.html" rel="noopener noreferrer"&gt;Java&lt;/a&gt; and &lt;a href="https://getsnap.dev/screenshot-api/csharp.html" rel="noopener noreferrer"&gt;C#&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Feature request &amp;amp; pricing changes
&lt;/h2&gt;

&lt;p&gt;APIs change fast. If any pricing or feature detail in this post is out of date, please email &lt;a href="mailto:support@getsnap.dev"&gt;support@getsnap.dev&lt;/a&gt;. We'd rather correct our own post than misrepresent a competitor.&lt;/p&gt;

&lt;h2&gt;
  
  
  Related reading
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://getsnap.dev/blog/puppeteer-vs-playwright-2026.html" rel="noopener noreferrer"&gt;Puppeteer vs Playwright in 2026&lt;/a&gt; — if you self-host instead of buying, which library to build on&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://getsnap.dev/blog/chrome-devtools-screenshot-limits.html" rel="noopener noreferrer"&gt;Where Chrome DevTools stops&lt;/a&gt; — the free option, and the four things it cannot do&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://getsnap.dev/blog/ai-agents-vs-screenshot-api.html" rel="noopener noreferrer"&gt;AI agents can drive a browser&lt;/a&gt; — the other alternative people reach for, and where it lands&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://getsnap.dev/blog/best-screenshot-api-2026.html" rel="noopener noreferrer"&gt;getsnap.dev&lt;/a&gt;. I work on getSnap.dev, one of the products compared above. Every figure is from each vendor's own published pricing, dated in the original.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>api</category>
      <category>comparison</category>
      <category>tooling</category>
    </item>
    <item>
      <title>A 503 that could not happen: finding a Fastify lifecycle bug</title>
      <dc:creator>rokaskve</dc:creator>
      <pubDate>Fri, 04 Dec 2026 11:39:12 +0000</pubDate>
      <link>https://dev.to/rokaskve/a-503-that-could-not-happen-finding-a-fastify-lifecycle-bug-9p5</link>
      <guid>https://dev.to/rokaskve/a-503-that-could-not-happen-finding-a-fastify-lifecycle-bug-9p5</guid>
      <description>&lt;p&gt;We shipped a change that signs our render links with a secret held in the server environment instead of a value stored in the database. It has a guard: if the secret is missing, refuse to issue a link rather than fall back to something weaker. The guard returns &lt;code&gt;503&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Then production returned a &lt;code&gt;503&lt;/code&gt; for a request that should never have reached that guard — and the body attached to it belonged to a different response entirely.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="no"&gt;POST&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;v1&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;render&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;link&lt;/span&gt;     &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;invalid&lt;/span&gt; &lt;span class="no"&gt;API&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="no"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="mi"&gt;503&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"unauthorized"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s2"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"Invalid API key"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A 503 status carrying a 401 body. That combination is not supposed to be constructible. This is how it happened, including the four attempts to reproduce it that all failed, and the Fastify behaviour underneath.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reading the mismatch
&lt;/h2&gt;

&lt;p&gt;The body is unambiguous: &lt;code&gt;"Invalid API key"&lt;/code&gt; is the string our authentication middleware sends. Our global error handler has its own wording for a missing key — &lt;code&gt;"Missing API key. Send it in the&lt;br&gt;
        x-api-key header."&lt;/code&gt; — so there was no doubt which code produced the body. Authentication ran, rejected the request, and replied.&lt;/p&gt;

&lt;p&gt;The status was the problem. &lt;code&gt;reply.code(503)&lt;/code&gt; appears exactly once in our entire codebase: inside the route handler, in the guard described above. For the status to be 503, that line had to execute. Which meant the handler ran &lt;em&gt;after&lt;/em&gt; the middleware had already sent a reply.&lt;/p&gt;

&lt;p&gt;Fastify does not do that. Replying from a hook halts the chain. It is in the documentation, in a sentence that leaves no room:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Replying from a hook implies that the hook chain is &lt;strong&gt;stopped&lt;/strong&gt; and the rest of the hooks and handlers are not executed. [...] If the hook is &lt;code&gt;async&lt;/code&gt;, &lt;code&gt;reply.send()&lt;/code&gt; &lt;strong&gt;must&lt;/strong&gt; be called &lt;em&gt;before&lt;/em&gt; the function returns or the promise resolves, otherwise, the request will proceed.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Our middleware calls &lt;code&gt;reply.send()&lt;/code&gt; synchronously, well before the function returns. By the documentation, the chain stops.&lt;/p&gt;
&lt;h2&gt;
  
  
  A better probe than the first one
&lt;/h2&gt;

&lt;p&gt;Before chasing the framework, we wanted a cheaper test of the claim "the handler ran". The handler's &lt;em&gt;first&lt;/em&gt; statement is a validation check that returns 400 when the request body has no &lt;code&gt;url&lt;/code&gt; and no &lt;code&gt;html&lt;/code&gt;, several lines before the 503 guard. So: send an invalid key with an empty body. If the handler is not running, the response is the middleware's 401. If it is running, the status becomes 400.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;invalid key + {"url": "..."}   -&amp;gt;  503   (the signing guard)
invalid key + {}               -&amp;gt;  400   (the body check, earlier in the handler)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both carried the 401 body. The status tracked exactly how far into the handler execution got. The handler was running, and the mismatch was it overwriting the status of a response already on its way out.&lt;/p&gt;

&lt;h2&gt;
  
  
  Four reproductions that failed
&lt;/h2&gt;

&lt;p&gt;Knowing &lt;em&gt;what&lt;/em&gt; was happening did not explain &lt;em&gt;why&lt;/em&gt;, and nothing is fixable until it reproduces. Four attempts, in increasing fidelity:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;A synthetic app&lt;/strong&gt; — an async hook that sends and returns, a handler that sets a different status. Handler skipped. Status 401. Correct.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The real middleware and the real route&lt;/strong&gt;, with the database and Redis mocked. Correct.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Over a real socket&lt;/strong&gt; rather than Fastify's &lt;code&gt;inject()&lt;/code&gt;, in case the in-process path differed. Correct.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The compiled output&lt;/strong&gt; — production runs &lt;code&gt;dist/&lt;/code&gt; from &lt;code&gt;tsc&lt;/code&gt;, not TypeScript through a test runner — against a real Redis and a real SQLite file. Still correct.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Four environments, none reproducing a thing that happened on every single request in production. At that point the useful question stops being "why is the framework misbehaving" and becomes "what is still different about my harness".&lt;/p&gt;

&lt;h2&gt;
  
  
  The difference
&lt;/h2&gt;

&lt;p&gt;Every probe had registered the route in isolation. Production registers it inside an application that also sets up CORS, Swagger, metrics and logging. So we ran the actual compiled application — the real &lt;code&gt;dist/index.js&lt;/code&gt;, nothing stubbed but the network it talks to.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bogus key + no url  -&amp;gt;  status=400  body={"error":"unauthorized",...}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reproduced. From there it was a bisect. Not CORS. Not Swagger. Not the metrics hooks. The reproduction needed the request-id hook &lt;em&gt;and&lt;/em&gt; the 5xx alerting hook — and the only thing those two have in common is that both are &lt;code&gt;onSend&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two hooks
&lt;/h2&gt;

&lt;p&gt;Stripped of our code entirely, it is this:&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;import&lt;/span&gt; &lt;span class="nc"&gt;Fastify&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'fastify'&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;onSendCount&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;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Fastify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;handlerRan&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;

  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;onSendCount&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addHook&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'onSend'&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="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;reply&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;preHandler&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="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;reply&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="n"&gt;reply&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;code&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;401&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'unauthorized'&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="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;handler&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="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;reply&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="n"&gt;handlerRan&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;reply&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;code&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'handler ran'&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="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;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;inject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'GET'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&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="n"&gt;app&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="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="sb"&gt;`onSend=${onSendCount} handlerRan=${handlerRan} status=${res.statusCode}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;for&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;n&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&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="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;
&lt;code&gt;onSend&lt;/code&gt; hooks&lt;/th&gt;
&lt;th&gt;Handler skipped?&lt;/th&gt;
&lt;th&gt;Status&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;yes&lt;/td&gt;
&lt;td&gt;401 — correct&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;yes&lt;/td&gt;
&lt;td&gt;401 — correct&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;2&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;td&gt;400&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;td&gt;400&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Fastify 5.12.5, Node 22. Adding a second &lt;code&gt;onSend&lt;/code&gt; hook changes whether replying from a hook halts the request.&lt;/p&gt;

&lt;p&gt;Narrowing further, both halves matter. It needs the replying hook to be &lt;code&gt;async&lt;/code&gt; &lt;em&gt;and&lt;/em&gt; at least two &lt;code&gt;async&lt;/code&gt; &lt;code&gt;onSend&lt;/code&gt; hooks. Callback-style &lt;code&gt;onSend&lt;/code&gt; hooks do not trigger it; neither does the same number of &lt;code&gt;onRequest&lt;/code&gt; or &lt;code&gt;preValidation&lt;/code&gt; hooks. And it is not specific to &lt;code&gt;preHandler&lt;/code&gt; — with two async &lt;code&gt;onSend&lt;/code&gt; hooks registered, replying from &lt;code&gt;onRequest&lt;/code&gt;, &lt;code&gt;preParsing&lt;/code&gt;, &lt;code&gt;preValidation&lt;/code&gt; or &lt;code&gt;preHandler&lt;/code&gt; all let the handler run.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it meant for us, stated plainly
&lt;/h2&gt;

&lt;p&gt;Our application registers exactly two &lt;code&gt;onSend&lt;/code&gt; hooks. So every authenticated route was running its handler for requests that authentication had already rejected.&lt;/p&gt;

&lt;p&gt;The impact was bounded, and the bound was luck rather than design. Handlers dereference the authenticated key within a few lines and throw when it is missing, and the resulting error reply is discarded because a response was already sent. Nothing was authorised, no capture ran, no quota moved, and no client ever received a success body it should not have. But any statement &lt;em&gt;before&lt;/em&gt; that first dereference did execute on rejected requests, and that is not a property anyone should be relying on.&lt;/p&gt;

&lt;p&gt;It was invisible for the same reason. The body a client receives is always the correct rejection. Only the status changes, and only on a handler that sets one before touching the key. Exactly one of our routes does that. Our other endpoints either reject at schema validation before any handler runs, or throw before setting a status. It took a missing environment variable, producing a conspicuous 503 on precisely that route, to expose any of it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix is one line per rejection
&lt;/h2&gt;

&lt;p&gt;Return the reply instead of sending and returning nothing:&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="c1"&gt;// before&lt;/span&gt;
&lt;span class="n"&gt;reply&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;code&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;401&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'unauthorized'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt;

&lt;span class="c1"&gt;// after&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;reply&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;code&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;401&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'unauthorized'&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;This is Fastify's documented idiom, it costs nothing, and it halts correctly regardless of how many &lt;code&gt;onSend&lt;/code&gt; hooks exist.&lt;/p&gt;

&lt;p&gt;One place deliberately did &lt;em&gt;not&lt;/em&gt; get the change. Our rate limiters are helpers called from inside handlers that return a &lt;code&gt;boolean&lt;/code&gt;, and their callers branch on 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="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&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;ipRateLimit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reply&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;opts&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="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;reply&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Returning the reply object from those is truthy, which inverts the test and lets rate-limited requests straight through. The first pass of the fix did exactly that, mechanically, across every &lt;code&gt;reply.code(...).send(...)&lt;/code&gt; in the middleware directory. It was caught before committing, and the code now carries a comment explaining why those two functions are different. A fix applied by pattern-match is still a change you have to read.&lt;/p&gt;

&lt;h2&gt;
  
  
  The test registers two onSend hooks on purpose
&lt;/h2&gt;

&lt;p&gt;The regression test builds an application with both hooks, because without them it passes against the broken code and proves nothing. We checked that directly: reverting a single rejection branch makes it fail, and restoring the fix makes it pass. A test you have not watched fail is a test you do not know the meaning of.&lt;/p&gt;

&lt;h2&gt;
  
  
  It is older than we thought, and it used to be loud
&lt;/h2&gt;

&lt;p&gt;The original report called this 5.12.5 behaviour, because that is the version we were on. Running the reproduction against every major since &lt;code&gt;fastify@4.0.0&lt;/code&gt; says otherwise: the halting behaviour is identical all the way back. Two async &lt;code&gt;onSend&lt;/code&gt; hooks have always been enough to let the handler run.&lt;/p&gt;

&lt;p&gt;What &lt;em&gt;did&lt;/em&gt; change is the symptom, and the boundary is exact:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Version&lt;/th&gt;
&lt;th&gt;Handler halts?&lt;/th&gt;
&lt;th&gt;What you see&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;4.0.0 – 5.10.0&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Uncaught &lt;code&gt;ERR_HTTP_HEADERS_SENT&lt;/code&gt;, process exits 1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5.11.0 – 5.12.5&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Nothing. The status is overwritten and the process is fine.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Before 5.11.0, the handler writing to an already-sent reply threw out of a promise and took the process down. From 5.11.0 the throw is gone and the chain still runs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;That is the part worth sitting with.&lt;/strong&gt; A crash is a bug report on its first occurrence. A silently wrong status code is a thing you run for weeks. The fix that removed the noise is the reason this survived in our production long enough to be confusing — and we only found it because a status code disagreed with its own body, which is the one trace it still leaves.&lt;/p&gt;

&lt;p&gt;The reproduction and the full version matrix are in the repository at &lt;code&gt;ops/fastify-7090/&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reported upstream
&lt;/h2&gt;

&lt;p&gt;Filed as &lt;a href="https://github.com/fastify/fastify/issues/7090" rel="noopener noreferrer"&gt;fastify/fastify#7090&lt;/a&gt; with the minimal reproduction, the narrowing matrix and the list of affected hooks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Checked 2026-11-25, and the answer arrived.&lt;/strong&gt; A maintainer replied on 24 October with &lt;a href="https://github.com/fastify/fastify/issues/7090#issuecomment-6386241840" rel="noopener noreferrer"&gt;one line&lt;/a&gt; — “This is an application bug to me” — and a diff putting &lt;code&gt;return&lt;/code&gt; in front of the &lt;code&gt;reply.code(401).send(...)&lt;/code&gt;. The test-only pull request that pinned the two-hook boundary (&lt;a href="https://github.com/fastify/fastify/pull/7129" rel="noopener noreferrer"&gt;#7129&lt;/a&gt;) was closed on 14 November without comment. The issue itself is still open.&lt;/p&gt;

&lt;p&gt;We are not going to argue with that. It is our bug, by the only definition that matters: our line, our outage. The update this post needs is not a rebuttal, it is the reason the line was written that way, and that reason is still sitting in the documentation. &lt;code&gt;docs/Reference/Hooks.md&lt;/code&gt; reads, today:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“If the hook is &lt;code&gt;async&lt;/code&gt;, &lt;code&gt;reply.send()&lt;/code&gt; &lt;strong&gt;must&lt;/strong&gt; be called &lt;em&gt;before&lt;/em&gt; the function returns or the promise resolves, otherwise, the request will proceed. When &lt;code&gt;reply.send()&lt;/code&gt; is called outside of the promise chain, it is important to &lt;code&gt;return reply&lt;/code&gt; otherwise the request will be executed twice.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Read it the way someone writing a hook reads it. Calling &lt;code&gt;reply.send()&lt;/code&gt; inside the async function &lt;em&gt;is&lt;/em&gt; calling it before the promise resolves, so the first sentence says you are done. &lt;code&gt;return reply&lt;/code&gt; is then introduced for the other situation — sending from outside the promise chain — and the example directly beneath it is a &lt;code&gt;setImmediate&lt;/code&gt;, which is exactly that other situation. Our handler was the first case. The first case is the one that does not work.&lt;/p&gt;

&lt;p&gt;Why it does not work was then explained by two people who are not us, and that exchange is worth more than anything above it. &lt;code&gt;Reply&lt;/code&gt; implements &lt;code&gt;then&lt;/code&gt;, so returning or awaiting it waits for the response stream to actually end. A bare &lt;code&gt;reply.send()&lt;/code&gt; returns &lt;code&gt;Promise.resolve(undefined)&lt;/code&gt; instead, and the hook runner advances on the next microtask tick. &lt;code&gt;reply.sent&lt;/code&gt; is just &lt;code&gt;raw.writableEnded&lt;/code&gt;, which is set only after the last &lt;code&gt;onSend&lt;/code&gt; hook has run. With zero or one &lt;code&gt;onSend&lt;/code&gt; hooks the response has ended by that tick and the chain halts. With two, the chained &lt;code&gt;onSend&lt;/code&gt; promises need more ticks than the hook did, &lt;code&gt;writableEnded&lt;/code&gt; is still &lt;code&gt;false&lt;/code&gt; when &lt;code&gt;preHandlerCallback&lt;/code&gt; tests it, and the handler runs (&lt;a href="https://github.com/fastify/fastify/issues/7090#issuecomment-6759784930" rel="noopener noreferrer"&gt;SameRainbows’ walk-through&lt;/a&gt;, with a table across 0–3 hooks and all three calling styles).&lt;/p&gt;

&lt;p&gt;That is the sentence we were missing in October: &lt;strong&gt;the halt is inferred from a fact about the response instead of being carried as a fact about the control flow.&lt;/strong&gt; Everything odd about this bug follows from it — why a hook in an unrelated file changes the semantics of a hook in this one, why the fix is per-rejection rather than central, and why it went quiet at 5.11.0 rather than being fixed there. Someone else in the thread had &lt;a href="https://github.com/fastify/fastify/issues/7090#issuecomment-6705347926" rel="noopener noreferrer"&gt;shipped the same defect&lt;/a&gt; in a different HTTP framework’s filter chain, produced the identical symptom, and settled it by tracking the halt on the chain state explicitly. A response fact and a control-flow fact are not the same fact, and conflating them is what makes the outcome depend on a registration count.&lt;/p&gt;

&lt;p&gt;So: closed as code, and we think correctly. The documentation is the half that was actually wrong, so we sent a patch for it — &lt;a href="https://github.com/fastify/fastify/pull/7271" rel="noopener noreferrer"&gt;fastify/fastify#7271&lt;/a&gt; rewrites those two sentences to require &lt;code&gt;return reply&lt;/code&gt; in an &lt;code&gt;async&lt;/code&gt; hook unconditionally. Matteo Collina approved it on 26 November. That is the loop closed: the next person to write the line we wrote will read something that tells them not to.&lt;/p&gt;

&lt;p&gt;The behaviour itself is unchanged, and we re-ran the reproduction on &lt;strong&gt;5.12.8 on 27 November&lt;/strong&gt; to be sure rather than to assume. Two &lt;code&gt;async&lt;/code&gt; &lt;code&gt;onSend&lt;/code&gt; hooks still produce a &lt;code&gt;400&lt;/code&gt; carrying the &lt;code&gt;401&lt;/code&gt; body; zero or one still do not. If you only take one thing from this post, take the rule rather than the diagnosis: in an &lt;code&gt;async&lt;/code&gt; hook, &lt;code&gt;return reply&lt;/code&gt; or &lt;code&gt;await&lt;/code&gt; it, every time, regardless of what else is registered. It costs six characters and it is unconditionally correct.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three things worth keeping
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;A status code that disagrees with its body is a lifecycle problem.&lt;/strong&gt; Nothing else produces that shape. Two pieces of code both believed they owned the response, and reading the body told us which one actually sent it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"Cannot reproduce" is a statement about your harness.&lt;/strong&gt; Four increasingly faithful environments all said the bug did not exist while it was happening on every production request. The move that worked was not thinking harder about the framework; it was enumerating what the harness still did not have, and running the real application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Documented behaviour is still worth verifying.&lt;/strong&gt; The documentation says replying from a hook stops the chain. It does — under a condition the documentation does not mention, which nothing in our code could have told us about.&lt;/p&gt;

&lt;h2&gt;
  
  
  Related reading
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://getsnap.dev/blog/audit-our-own-site-60-violations.html" rel="noopener noreferrer"&gt;We audited our own site and found 60 WCAG violations&lt;/a&gt; — the same exercise pointed at the front end instead of the server&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://getsnap.dev/blog/team-billing-phase-2.html" rel="noopener noreferrer"&gt;Team-owned Stripe subscriptions in three endpoints&lt;/a&gt; — another change that had to survive contact with production&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://getsnap.dev/blog/fastify-hook-halt-bug.html" rel="noopener noreferrer"&gt;getsnap.dev&lt;/a&gt;. I work on getSnap.dev, a screenshot and PDF API. This bug came out of running it, and the upstream issue and docs fix linked above are public.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>fastify</category>
      <category>debugging</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
