insight Simon Willison 2026-08-20T15:37 正文 ok 248 words

基于 Bun 1.4 新版 Bun.WebView 构建类 shot-scraper 的 JSON API

英文标题:A shot-scraper-style JSON API on Bun 1.4's new Bun.WebView

Bun 1.4 已发布,这是 Bun 在数月前完成备受关注的 Rust 重写后的首个稳定版本。该版本新增 1,517 项来自 Node.js 测试套件的测试、修复超过 2,900 个问题,并宣称将空闲 CPU 使用量降低 5 倍、内存使用量最多降低 35%、Linux 启动速度提升 50%。作者尤其关注新增的 Bun.WebView:它可通过 macOS WebKit 或 Chrome DevTools Protocol(CDP)控制本地 Chromium,为 Bun 核心带来浏览器自动化能力。作者借助 Claude Code 构建了一个可加载网页并执行 JavaScript 的 JSON API 原型,测试显示,在复杂网页上运行完整 Chrome 的服务大约需要 192MB 至 256MB 容器内存。
打开原文相关 2.4 · 机会 2

中文

今天,备受期待的 Bun 1.4 发布,这是在数月前那次备受争议的 Rust 重写之后推出的首个稳定版本。

有意思的是,发布说明淡化了 Rust 重写,转而介绍了一系列令人眼花缭乱的新功能,并宣称额外修复了 2,900 个问题:

Bun 1.4 新增了来自 Node.js 测试套件的 1,517 项测试——这是自 Bun 1.0 以来 Node.js 兼容性提升幅度最大的一次。Bun v1.4 还修复了超过 2,900 个问题。它将空闲 CPU 使用量降低了 5 倍,将内存使用量最多降低 35%,并使 Linux 上的启动速度提升 50%。它新增了 Bun.Image、Bun.WebView、Bun.markdown、Bun.cron()、Bun.Terminal、bun run --parallel、bun test --parallel、bun audit fix、bun dedupe 和 bun prune。此外,它还将 Bun 从 Zig 重写为 Rust。

在这些功能中,最吸引我注意的是 Bun.WebView。它通过 macOS WebKit,或通过 Chrome DevTools Protocol(CDP)控制本地 Chromium 进程,为 Bun 核心增加了一等的浏览器自动化支持。

我让 Claude Code for web 构建了一个 Web API 原型:它可以加载网页,然后在页面上执行 JavaScript。这个原型的灵感来自我的 shot-scraper javascript CLI 工具——部分目的也是想了解,这类服务需要多少 RAM。

这是那份 TypeScript 服务器实现。使用 cgroups 测试表明,要让完整 Chrome 处理复杂网页,它似乎需要一个具备 192MB 至 256MB 内存的容器。

English / 原文

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.