Bun 1.4 的 Bun.WebView 如何实现 shot-scraper 风格的 JSON API

Simon Willison 博客·2026-08-20 23:37·11天前·Simon Willison
AI 导读

一个约 150 行的零依赖 TypeScript 服务展示了 Bun 1.4 实验性 Bun.WebView 可提供 shot-scraper 风格的 JSON API,无需 Puppeteer 或 Playwright 即可执行 JavaScript 并截取 PNG/JPEG/WebP 截图。

Simon Willison 博客
46AI 编辑部评分,满分 100

Bun 1.4 的 Bun.WebView 如何实现 shot-scraper 风格的 JSON API

2026-08-20 23:37· 11天前· Simon Willison
AI 导读

一个约 150 行的零依赖 TypeScript 服务展示了 Bun 1.4 实验性 Bun.WebView 可提供 shot-scraper 风格的 JSON API,无需 Puppeteer 或 Playwright 即可执行 JavaScript 并截取 PNG/JPEG/WebP 截图。

— A zero-dependency, roughly 150-line TypeScript service demonstrates that Bun 1.4’s experimental `Bun.WebView` can provide a shot-scraper-style JSON API for JavaScript evaluation and PNG/JPEG/WebP screenshots without Puppeteer or Playwright. It creates one browser tab per request, supporting concurrency while returning page results and errors as JSON through `/javascript`, `/screenshot`, and `/healthz`.

Today saw the long awaited release of Bun 1.4, the first stable version since the infamous Rust rewrite a few months ago.

Interestingly, the Rust rewrite was downplayed in the release notes, which introduced a bewildering array of new features and claimed 2,900 additional bug fixes:

Bun 1.4 adds +1,517 tests from the Node.js test suite - our biggest jump in Node.js compatibility since Bun 1.0. Bun v1.4 also fixes over 2,900 issues. It reduces idle CPU usage by 5x, reduces memory usage by up to 35%, and starts 50% faster on Linux. It adds Bun.Image, Bun.WebView, Bun.markdown, Bun.cron(), Bun.Terminal, bun run --parallel, bun test --parallel, bun audit fix, bun dedupe, and bun prune. And it rewrites Bun from Zig to Rust.

Of these the one that most caught my eye was Bun.WebView, which adds first class support for browser automation to Bun core using either macOS WebKit or control of a local Chromium process via the Chrome DevTools Protocol (CDP).

I had Claude Code for web build a prototype of a web API providing the ability to load a web page and then execute JavaScript against it, inspired by my shot-scraper javascript CLI tool - partly to see how much RAM would be needed by such a service.

Here's that TypeScript server implementation, which appears to need a 192MB-256MB container to run a full Chrome against complex web pages - tested using cgroups.

20th August 2026

来源:Simon Willison 博客· simonwillison.net