Installation
Add kmpwright-core (and optionally kmpwright-compose) to a Kotlin Multiplatform, Android, iOS or JVM project, with the minimum versions and threading rules each platform needs.
Version 0.0.1 is available on Maven Central. This is an alpha release; APIs and platform coverage may change.
Add the library
Add one dependency to commonMain.dependencies in your module's build.gradle.kts:
implementation("io.github.bernaferrari:kmpwright-core:0.0.1")Gradle selects the matching platform variant. Your project must include mavenCentral() in its repositories. For a complete Gradle example, see Kotlin Multiplatform below.
| Artifact | Coordinates | Targets |
|---|---|---|
| Core | io.github.bernaferrari:kmpwright-core:0.0.1 | Android, iOS (arm64 device and simulator), JVM, JS |
| Compose wrapper (optional) | io.github.bernaferrari:kmpwright-compose:0.0.1 | Android only |
The Kotlin/JS artifact supports the website demo's browser bridge. See the capability matrix for backend differences.
Public packages are com.bernaferrari.kmpwright.core and com.bernaferrari.kmpwright.compose.
Minimum versions
| Platform | Minimum | Source |
|---|---|---|
| Android | API 26 (Android 8.0), minSdk = 26 | kmpwright-core/build.gradle.kts |
| iOS | iOS 15.0, arm64 device and arm64 simulator only (no Intel simulator) | kmpwright-core/build.gradle.kts |
| JVM | JDK 17 | project toolchain baseline |
| JVM browser | An installed Chrome or Chromium executable, or a CDP endpoint | launchBrowser, CdpConfig |
Video recording on the JVM also needs FFmpeg on PATH.
Kotlin Multiplatform
Add the core to commonMain. Gradle picks the right Android, iOS or JVM variant per target.
// build.gradle.kts
repositories { mavenCentral() }
kotlin {
sourceSets {
commonMain.dependencies {
implementation("io.github.bernaferrari:kmpwright-core:0.0.1")
}
androidMain.dependencies {
// Optional: Compose WebView wrapper (Android only).
implementation("io.github.bernaferrari:kmpwright-compose:0.0.1")
}
}
}Your shared code then works with Browser, Page and Locator. Each platform source set creates the PlatformContext (AndroidPlatformContext, IOSPlatformContext, JvmPlatformContext) because those wrap platform objects.
Android-only app
// app/build.gradle.kts
dependencies {
implementation("io.github.bernaferrari:kmpwright-core:0.0.1")
implementation("io.github.bernaferrari:kmpwright-compose:0.0.1") // optional
}Declare network access in your AndroidManifest.xml. The library does not add it for you:
<uses-permission android:name="android.permission.INTERNET" />To inspect the automated WebView from chrome://inspect during development, call WebView.setWebContentsDebuggingEnabled(true) (the sample app does this).
iOS
You have two options.
Kotlin Multiplatform. Add the dependency to commonMain (above) and use KMPwright from iosMain or shared code. Your shared framework exports whatever you choose; the KMPwright API itself is Kotlin, so drive it from Kotlin code.
Swift/Xcode via XCFramework. You can build a static KmpwrightCore.xcframework (module name KmpwrightCore) from source. CocoaPods distribution is not supported:
The standalone Swift/Xcode XCFramework release asset is not published yet. Build it from source using the command below. KMP consumers can already use the Maven dependency.
Add KmpwrightCore.xcframework to your Xcode target and set Do Not Embed (it is a static library).
Build for a device and for the arm64 simulator. The bundle contains only the arm64-apple-ios and arm64 simulator slices and declares iOS 15.0 as its minimum deployment target.
From source, the same XCFramework is produced by:
./gradlew :kmpwright-core:packageKmpwrightCoreReleaseXCFramework
# output: kmpwright-core/build/XCFrameworks/release/KmpwrightCore.xcframeworkSee docs/releasing.md for the verification steps.
JVM
// build.gradle.kts
dependencies {
implementation("io.github.bernaferrari:kmpwright-core:0.0.1")
}On the JVM, KMPwright talks CDP to Chromium. Either point launchBrowser at a Chrome/Chromium executable, connect to an existing ws://…/devtools/browser/… endpoint, or use a cloud provider. See the JVM platform page.
Threading rules
KMPwright's API is suspend and can be called from any dispatcher, but the mobile WebViews themselves are single-threaded.
- Create the
Browseron the main thread.Browser(AndroidPlatformContext(...))checks this and throwsIllegalStateException("must be called on the Android main thread") otherwise. Create it fromActivity,Fragmentor Compose code, or wrap it inwithContext(Dispatchers.Main). - After construction, page and locator calls can come from any dispatcher; KMPwright confines WebView work to the main looper internally.
browser.newPage()creates a new managedWebViewon the main thread for you.
Next
Introduction
KMPwright is a Kotlin Multiplatform browser automation library with a Playwright-style API and agent-browser commands for Android WebView, iOS WKWebView and Chromium on the JVM.
Quick start
Attach KMPwright to an Android WebView or iOS WKWebView, or launch Chromium on the JVM, then click, assert, screenshot and run your first agent loop.