coding by Ryan Caldwell

Lightweight Web Scraping with Bun.WebView API

Explores how to use Bun's WebView API for lightweight web scraping, enabling developers to extract data from websites efficiently using a minimal JavaScript

 method: 'POST',
 headers: { 'Content-Type': 'application/json' },
 body: JSON.stringify({
 url: 'https://example.com',
 script: 'document.title'
 })
});

This request hits a lightweight JSON API that executes JavaScript against web pages and returns the result - no Puppeteer, no Playwright, just Bun’s experimental Bun.WebView feature introduced in version 1.4.

The Problem It Solves

Browser automation typically requires heavy dependencies like Puppeteer or Playwright, which bundle entire browser engines and add significant overhead to projects. For simple tasks like evaluating JavaScript on a page or capturing screenshots, these tools can feel like using a sledgehammer to crack a nut.

The shot-scraper-style API built on Bun.WebView addresses this by providing a zero-dependency service for common browser automation tasks. According to the implementation, the entire service runs in roughly 150 lines of TypeScript, creating one browser tab per request to support concurrent operations while keeping the footprint minimal.

How It Works

The service exposes three endpoints that return JSON responses. The /javascript endpoint accepts a URL and a script, executes the JavaScript against the loaded page, and returns the result. The /screenshot endpoint captures page renders in PNG, JPEG, or WebP formats. A /healthz endpoint provides service status checks.

Each request spawns a dedicated browser tab through Bun.WebView, which handles the rendering and JavaScript execution. This one-tab-per-request model enables concurrent processing without tab state bleeding between requests. Errors are caught and returned as JSON rather than crashing the service, making the API suitable for production scenarios where graceful degradation matters.

The experimental Bun.WebView API arrived in Bun 1.4, which shipped in August 2026 as the first stable release following a Rust rewrite completed months earlier. The release notes highlighted over 2,900 bug fixes and claimed significant performance improvements: 5x reduction in idle CPU usage, up to 35% less memory consumption, and 50% faster startup times on Linux. The version also added 1,517 tests from the Node.js test suite, representing what the team called their biggest compatibility jump since Bun 1.0.

Setup Guide

Since the service has zero dependencies beyond Bun itself, setup involves installing Bun 1.4 or later and running the TypeScript file directly:

The service listens on localhost:3000 by default. To evaluate JavaScript on a page, POST to /javascript with a JSON body containing url and script fields. For screenshots, POST to /screenshot with the target URL and optional format parameters.

Because Bun.WebView remains experimental in version 1.4, the API should be tested thoroughly before production deployment. The experimental status means the underlying implementation may change in future Bun releases.

Ecosystem

This approach fits scenarios where full browser automation frameworks feel excessive. Developers building monitoring tools, content scrapers, or visual regression systems can integrate lightweight browser capabilities without bundling Chromium or managing separate browser processes.

The shot-scraper reference in the project name points to a similar tool in the Python ecosystem that provides command-line browser automation. By bringing comparable functionality to Bun through Bun.WebView, the TypeScript implementation offers JavaScript-native developers a familiar pattern without crossing language boundaries.

The timing aligns with Bun’s broader push for Node.js compatibility. The 1.4 release’s emphasis on passing Node.js test suite cases suggests the runtime aims to become a drop-in replacement for Node in more contexts, with features like Bun.WebView extending beyond strict compatibility into new capabilities that leverage Bun’s architecture.