Playwright

0.1.0

Playwright for Swift is a browser automation library to control Chromium, Firefox and WebKit with a single API.
m1guelpf/swift-playwright

What's New

🎭 Playwright for Swift

Test

Playwright is a Swift library to automate Chromium, Firefox and WebKit with a single API. Playwright is built to enable cross-browser web automation that is ever-green, capable, reliable and fast.

Installation

Add swift-playwright to your Package.swift:

dependencies: [
    .package(url: "https://github.com/m1guelpf/swift-playwright.git", from: "0.1.0"),
],
targets: [
    .target(name: "MyApp", dependencies: [
        .product(name: "Playwright", package: "swift-playwright"),
    ]),
]

Then install the Playwright driver and browsers:

# Download the Playwright driver (~40MB, one-time setup)
swift package install-playwright

# Install browsers (requires Node.js)
npx playwright install

Quick Start

import Playwright

let playwright = try await Playwright.launch()
let browser = try await playwright.chromium.launch()
let page = try await browser.newPage()

// Navigate and read content
let response = try await page.goto("https://example.com")
print(try await page.title()) // "Example Domain"

// Find and interact with elements
try await page.locator("input[name=q]").fill("swift playwright")
try await page.getByRole(.button, name: "Search").click()

// Run JavaScript
let result = try await page.evaluate("1 + 1", as: Int.self)

// Capture a screenshot
let png = try await page.screenshot()

try await browser.close()
await playwright.close()

How It Works

swift-playwright works by communicating with the Node.js Playwright server, same as the official Python, Java, and .NET drivers:

┌─────────────────────────────────────────────────┐
│ Playwright (Swift API)                          │
├─────────────────────────────────────────────────┤
│ JSON-RPC over stdio                             │
├─────────────────────────────────────────────────┤
│ Playwright Server (Node.js)                     │
├───────────────┬───────────────┬─────────────────┤
│   Chromium    │    Firefox    │     WebKit      │
└───────────────┴───────────────┴─────────────────┘

License

This project is licensed under the MIT License - see the LICENSE file for details.

Description

  • Swift Tools 6.1.0
View More Packages from this Author

Dependencies

Last updated: Sat Apr 25 2026 12:45:12 GMT-0900 (Hawaii-Aleutian Daylight Time)