惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
V
V2EX
博客园 - 【当耐特】
WordPress大学
WordPress大学
爱范儿
爱范儿
美团技术团队
宝玉的分享
宝玉的分享
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
小众软件
小众软件
量子位
Hugging Face - Blog
Hugging Face - Blog
B
Blog RSS Feed
Recorded Future
Recorded Future
Engineering at Meta
Engineering at Meta
雷峰网
雷峰网
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
M
MIT News - Artificial intelligence
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 聂微东
H
Hackread – Cybersecurity News, Data Breaches, AI and More
腾讯CDC
大猫的无限游戏
大猫的无限游戏
Jina AI
Jina AI
博客园 - 叶小钗
GbyAI
GbyAI
Y
Y Combinator Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
F
Full Disclosure
G
Google Developers Blog
D
Docker
T
Tailwind CSS Blog
C
Check Point Blog
Last Week in AI
Last Week in AI
人人都是产品经理
人人都是产品经理
T
The Blog of Author Tim Ferriss
B
Blog
博客园 - 三生石上(FineUI控件)
博客园 - Franky
H
Help Net Security
MyScale Blog
MyScale Blog
U
Unit 42
D
DataBreaches.Net
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
I
InfoQ
阮一峰的网络日志
阮一峰的网络日志
The GitHub Blog
The GitHub Blog
L
LangChain Blog
有赞技术团队
有赞技术团队
Martin Fowler
Martin Fowler
Microsoft Security Blog
Microsoft Security Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
How to build a visual uptime monitor with Go and headless Chrome
SamReid · 2026-05-22 · via DEV Community

Most uptime monitors work by making an HTTP request and checking the response code. It's fast, cheap, and catches about half the things that actually go wrong in production.

The other half - JavaScript crashes, CDN serving stale cache, React hydration failures, missing elements - only show up when you look at what the page actually renders, not what the server returns.

This is a walkthrough of how I built GrabDiff - the visual monitoring piece specifically: capture screenshots with headless Chrome, diff them against a baseline, and send an alert when something looks wrong. I'll use Go and chromedp, which is what GrabDiff runs under the hood. If you'd rather just use the thing than build it, GrabDiff has a free plan with three monitors and no card required.


The architecture

The core loop is simple:

  1. On a schedule, capture a screenshot of a URL using headless Chrome
  2. Compare it pixel-by-pixel against a stored baseline image
  3. If the diff percentage exceeds a threshold, send an alert with the diff image attached
  4. Otherwise, store the new screenshot (optionally updating the baseline over time)

The interesting engineering is in steps 2 and 3 - getting the diff right and making alerts actionable.


Capturing screenshots with chromedp

chromedp is a Go library that controls Chrome via the DevTools Protocol. It handles the browser lifecycle, navigation, and screenshot capture.

package screenshot

import (
    "context"
    "time"

    "github.com/chromedp/chromedp"
)

func Capture(url string) ([]byte, error) {
    opts := append(chromedp.DefaultExecAllocatorOptions[:],
        chromedp.Flag("headless", true),
        chromedp.Flag("disable-gpu", true),
        chromedp.Flag("no-sandbox", true),
        chromedp.WindowSize(1280, 800),
    )

    allocCtx, cancel := chromedp.NewExecAllocator(context.Background(), opts...)
    defer cancel()

    ctx, cancel := chromedp.NewContext(allocCtx)
    defer cancel()

    ctx, cancel = context.WithTimeout(ctx, 30*time.Second)
    defer cancel()

    var buf []byte
    err := chromedp.Run(ctx,
        chromedp.Navigate(url),
        chromedp.Sleep(2*time.Second), // wait for JS to settle
        chromedp.FullScreenshot(&buf, 90),
    )
    if err != nil {
        return nil, err
    }
    return buf, nil
}

Enter fullscreen mode Exit fullscreen mode

A few things worth noting:

chromedp.Sleep(2*time.Second) is a blunt instrument but effective. For most pages, 2 seconds is enough for the JavaScript to execute and the page to reach a stable state. For pages with complex async data fetching you might need more, or you can use chromedp.WaitVisible to wait for a specific element.

chromedp.FullScreenshot captures the entire page height, not just the viewport. This is usually what you want for monitoring - you care about the whole page, not just what happens to be visible above the fold.

The 90 in FullScreenshot is JPEG quality. You can use chromedp.CaptureScreenshot instead for PNG (larger files, lossless).


Pixel diffing

Once you have a screenshot, you need to compare it against the baseline. The core operation is straightforward: decode both images, iterate over pixels, count how many differ by more than some per-channel threshold.

package screenshot

import (
    "bytes"
    "image"
    "image/color"
    _ "image/jpeg"
    "image/png"
    "math"
)

type DiffResult struct {
    DiffPercent float64
    DiffImage   []byte // PNG with differences highlighted
}

func Diff(baseline, current []byte) (*DiffResult, error) {
    baseImg, _, err := image.Decode(bytes.NewReader(baseline))
    if err != nil {
        return nil, err
    }
    currImg, _, err := image.Decode(bytes.NewReader(current))
    if err != nil {
        return nil, err
    }

    bounds := baseImg.Bounds()
    diffImg := image.NewRGBA(bounds)

    var diffPixels int
    totalPixels := bounds.Dx() * bounds.Dy()

    for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
        for x := bounds.Min.X; x < bounds.Max.X; x++ {
            br, bg, bb, _ := baseImg.At(x, y).RGBA()
            cr, cg, cb, _ := currImg.At(x, y).RGBA()

            // RGBA() returns values in [0, 65535]
            dr := math.Abs(float64(br) - float64(cr))
            dg := math.Abs(float64(bg) - float64(cg))
            db := math.Abs(float64(bb) - float64(cb))

            // threshold: 10% channel difference (6553 out of 65535)
            if dr > 6553 || dg > 6553 || db > 6553 {
                diffPixels++
                // highlight in red
                diffImg.Set(x, y, color.RGBA{R: 255, G: 0, B: 0, A: 255})
            } else {
                // keep original, slightly dimmed for context
                r, g, b, a := currImg.At(x, y).RGBA()
                diffImg.Set(x, y, color.RGBA{
                    R: uint8(r>>8) / 2,
                    G: uint8(g>>8) / 2,
                    B: uint8(b>>8) / 2,
                    A: uint8(a >> 8),
                })
            }
        }
    }

    diffPercent := float64(diffPixels) / float64(totalPixels) * 100

    var buf bytes.Buffer
    if err := png.Encode(&buf, diffImg); err != nil {
        return nil, err
    }

    return &DiffResult{
        DiffPercent: diffPercent,
        DiffImage:   buf.Bytes(),
    }, nil
}

Enter fullscreen mode Exit fullscreen mode

The diff image produced here shows changed pixels in red against a dimmed version of the current screenshot. This gives you at a glance where the change is - useful when you're trying to tell whether it's a minor layout shift or something more serious.

On threshold tuning: 1% is a good starting point for DiffPercent. Anything above that is almost certainly a real change. Below 0.1% is usually antialiasing noise. The right number depends on how dynamic your pages are.


Storing baselines

You need to store the baseline image somewhere. For a simple setup, an object store (S3, Backblaze B2, R2) works well - store the baseline under a key like {monitor_id}/baseline.jpg and update it when the user explicitly marks a new baseline.

// On first check, or when user resets the baseline
func (s *Store) SetBaseline(ctx context.Context, monitorID string, img []byte) error {
    key := fmt.Sprintf("%s/baseline.jpg", monitorID)
    return s.upload(ctx, key, img, "image/jpeg")
}

// On each check
func (s *Store) GetBaseline(ctx context.Context, monitorID string) ([]byte, error) {
    key := fmt.Sprintf("%s/baseline.jpg", monitorID)
    return s.download(ctx, key)
}

Enter fullscreen mode Exit fullscreen mode

One design decision worth thinking about: should the baseline update automatically? There are arguments either way. If you update it automatically after every "clean" check, you adapt to intentional page changes without manual intervention. If you require explicit resets, every change that slips past your threshold accumulates silently, and you'll eventually be diffing against something that looks nothing like your original known-good state.

GrabDiff requires explicit baseline resets. The reasoning: if you're updating the baseline automatically, you can drift into a state where "clean" means "whatever the page looked like yesterday" rather than "the page as I intended it." Explicit resets keep you honest.


Alerting

When DiffPercent exceeds your threshold, you want to notify someone fast. The two most useful channels are email (with the diff image attached) and webhooks.

type Alert struct {
    MonitorURL  string
    DiffPercent float64
    DiffImage   []byte
    CheckedAt   time.Time
}

func (s *EmailSender) SendAlert(ctx context.Context, to string, a Alert) error {
    body := fmt.Sprintf(
        "Visual change detected on %s\n\nDiff: %.2f%% of pixels changed\nChecked at: %s\n\nSee attached diff image.",
        a.MonitorURL, a.DiffPercent, a.CheckedAt.Format(time.RFC1123),
    )

    msg := gomail.NewMessage()
    msg.SetHeader("From", s.from)
    msg.SetHeader("To", to)
    msg.SetHeader("Subject", fmt.Sprintf("[GrabDiff] Change detected: %s", a.MonitorURL))
    msg.SetBody("text/plain", body)
    msg.AttachReader("diff.png", bytes.NewReader(a.DiffImage))

    return s.dialer.DialAndSend(msg)
}

Enter fullscreen mode Exit fullscreen mode

The diff image as an attachment is the key thing. An alert that just says "something changed" is nearly useless - you have to go look at the site yourself to know if it matters. An alert with a diff image attached tells you immediately whether this is "someone changed a button color" or "the entire main content area is gone."


Scheduling

For the scheduling loop, a simple approach is a ticker per monitor:

func (w *Worker) Run(ctx context.Context, monitor Monitor) {
    ticker := time.NewTicker(monitor.Interval)
    defer ticker.Stop()

    for {
        select {
        case <-ctx.Done():
            return
        case <-ticker.C:
            if err := w.check(ctx, monitor); err != nil {
                slog.Error("check failed", "monitor", monitor.ID, "err", err)
            }
        }
    }
}

Enter fullscreen mode Exit fullscreen mode

For anything beyond a handful of monitors, you'll want a proper job queue (River, Asynq, or even a simple Postgres-backed queue) rather than in-process goroutines. In-process schedulers don't survive restarts gracefully and make horizontal scaling harder.


The tradeoffs you'll hit in production

False positives from dynamic content. Timestamps, "last updated" labels, live counters, personalized greetings - these change on every screenshot and will trigger alerts constantly. You either need to mask those regions before diffing, or accept a higher threshold that makes you insensitive to small changes everywhere.

Headless Chrome resource usage. A single Chrome instance capturing a screenshot uses roughly 200-400MB of RAM and takes 3-8 seconds depending on page complexity. If you're running hundreds of monitors at frequent intervals, you need a pool of browser instances and careful scheduling to avoid spiking resource usage.

Authentication. Monitoring pages behind a login requires scripting the auth flow:

chromedp.Run(ctx,
    chromedp.Navigate("https://app.example.com/login"),
    chromedp.SendKeys(`input[name="email"]`, email),
    chromedp.SendKeys(`input[name="password"]`, password),
    chromedp.Click(`button[type="submit"]`),
    chromedp.WaitVisible(`#dashboard`),
    chromedp.Navigate(targetURL),
    chromedp.FullScreenshot(&buf, 90),
)

Enter fullscreen mode Exit fullscreen mode

This works, but it's fragile - login flows change, CAPTCHAs appear, session handling has edge cases. Plan for maintenance.

SSRF. If you're accepting URLs from users, you need to validate them against a blocklist before passing them to Chrome. Users will point your monitor at http://169.254.169.254/latest/meta-data/ or internal network addresses. Validate the resolved IP against RFC 1918 and link-local ranges before making any request.


What this gets you

A working version of the above - capture, diff, alert - is maybe 500 lines of Go. It'll catch blank pages, missing elements, major layout regressions, and CDN serving stale content. It won't catch every failure, but it catches the ones that HTTP monitors miss entirely.

If you want to run it yourself, the full approach is essentially what I described. If you'd rather not manage the Chrome instances and the storage and the scheduling, I built GrabDiff to handle all of that - it does the screenshot diffing, sends you the diff image in the alert, and handles SSL/domain/cron monitoring alongside the visual checks. Free plan, three monitors, no credit card.

The point is that "HTTP 200" and "the page works" are not the same thing, and the gap between them is where the interesting production failures live. Visual monitoring is how you close that gap.