A headless browser for Swift with full JavaScript execution on macOS and Linux.
Powered by Lightpanda — auto-downloaded on first run. No Chrome, no system dependencies.
ANTHROPIC: id=5023394008 title=Anthropic AI Safety Fellow
ANTHROPIC: id=5062955008 title=Applied Safety Research Engineer, Safeguards
SPOTIFY: id=31b21dea title=Apply
SPOTIFY: id=7426b51c title=Apply
5 tests, 3 suites, ~5 seconds.
Add to your Package.swift — that's it. Nothing else to install.
dependencies: [
.package(url: "https://github.com/ShawnBaek/SwiftHeadlessBrowser.git", from: "2.0.0")
].target(name: "YourApp", dependencies: ["SwiftHeadlessBrowser"])No brew install, no apt-get, no Chrome, no system dependencies.
On first run, the Lightpanda browser engine (~18MB) is automatically downloaded to ~/.cache/swift-headless-browser/. Subsequent runs use the cached binary instantly.
import SwiftHeadlessBrowser
let browser = try await HeadlessBrowser.create()
// Load a JS-rendered page
let page: HTMLPage = try await browser.open(
URL(string: "https://boards.greenhouse.io/anthropic")!
).execute()
// Extract job listings
let links: Result<[HTMLLink], ActionError> = page.findElements(.cssSelector("a[href*='/jobs/']"))
if case .success(let elements) = links {
for el in elements {
let id = el.href?.split(separator: "/").last ?? ""
let title = el.text ?? ""
print("id=\(id) title=\(title)")
}
}| Selector | Example |
|---|---|
.id("value") |
.id("header") |
.class("value") |
.class("job-card") |
.name("value") |
.name("email") |
.cssSelector("query") |
.cssSelector("a[href*='/jobs/']") |
.attribute("key", "val") |
.attribute("data-id", "123") |
.contains("key", "val") |
.contains("href", "/careers/") |
HeadlessBrowser.create()downloads Lightpanda to~/.cache/swift-headless-browser/(first run only, ~18MB)- Runs
lightpanda fetch --dump htmlas a subprocess — renders full JavaScript - SwiftSoup parses the returned HTML for element extraction
12 source files. Only dependency: SwiftSoup.
MIT License - See LICENSE file.