Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8b8d7d9
fix: delete the temporary profile when the browser stops
nathanfallet Nov 18, 2026
37d11fe
fix: address review of the temporary profile cleanup
nathanfallet Nov 18, 2026
333127e
refactor: try/finally instead of catching Throwable in the profile cl…
nathanfallet Nov 18, 2026
c16d593
test: delete the custom profile with retries, Windows keeps it locked…
nathanfallet Nov 18, 2026
17d33d9
test: profile kept while the browser runs, retries give up on a locke…
nathanfallet Nov 18, 2026
4249cf2
refactor: address static analysis findings on the profile cleanup
nathanfallet Nov 20, 2026
f1767f6
test: cover every temporary profile cleanup path
nathanfallet Nov 20, 2026
9db0274
fix: let stop() go on when the graceful close finds the connection cl…
nathanfallet Nov 20, 2026
2a5442a
style: address the remaining static analysis findings
nathanfallet Nov 20, 2026
d3e6a4c
fix: retry deleting the temporary profile for about 5 seconds
nathanfallet Nov 20, 2026
0cf43a9
refactor: avoid duplicated finally branches in browser start, and cov…
nathanfallet Nov 20, 2026
f6a45cd
style: suppress the generic catch that cleans up and rethrows
nathanfallet Nov 20, 2026
d3800f4
fix: do not close a browser create() only connected to, and keep the …
nathanfallet Nov 20, 2026
2c31c8e
test: wait for the page before reading its title or content, and prin…
nathanfallet Nov 21, 2026
c76056a
fix: delete the profile when a step of stop() fails, and let a config…
nathanfallet Nov 21, 2026
3cb11c1
fix: delete profile entries beyond MAX_PATH on Windows
nathanfallet Nov 21, 2026
992d18c
fix: never follow a link swapped in while deleting a profile on POSIX
nathanfallet Nov 21, 2026
ab0f0c8
fix: do not close a browser kdriver only connected to when the host e…
nathanfallet Nov 21, 2026
e491c9a
fix: run the blocking profile deletion on the I/O dispatcher
nathanfallet Nov 21, 2026
6f64f45
fix: keep the Windows process handle open for as long as the process …
nathanfallet Nov 21, 2026
7fbe24c
fix(deps): update Ktor to 3.4.3 for Curl WebSocket fixes on Linux native
nathanfallet Nov 21, 2026
d14312b
fix: keep a browser whose failed start already stopped it for the exi…
nathanfallet Nov 21, 2026
c084b26
test: share the native TabTest between macOS and Linux in posixTest
nathanfallet Nov 21, 2026
da5de06
test: load local pages in testMultipleBrowsersDiffUserData, and wait …
nathanfallet Nov 21, 2026
769f970
test: read the page title from the loaded document in testMultipleBro…
nathanfallet Nov 21, 2026
733fe74
style: address static analysis findings on the native profile deletion
nathanfallet Nov 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,23 @@ kotlin {
implementation(kotlin("test"))
implementation(libs.tests.mockk)
implementation(libs.tests.coroutines)
// Prints what kdriver logs (warnings and errors only, see simplelogger.properties),
// such as why a browser failed to start, instead of dropping it.
runtimeOnly(libs.tests.slf4jSimple)
}
}
val posixTest by creating {
dependsOn(commonTest.get())
}
val macosTest by getting {
dependsOn(posixTest)
dependencies {
implementation(kotlin("test"))
implementation(libs.tests.coroutines)
}
}
val linuxTest by getting {
dependsOn(posixTest)
dependencies {
implementation(kotlin("test"))
implementation(libs.tests.coroutines)
Expand Down
23 changes: 22 additions & 1 deletion core/src/commonMain/kotlin/dev/kdriver/core/browser/Browser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ interface Browser {

/**
* Launches the actual browser
*
* If the browser process this instance launched has died, a new browser is started on the same
* configuration and profile and returned: use that instance from then on. It owns the process and
* the temporary profile, so [stop] it rather than this one.
*/
suspend fun start(): Browser

Expand Down Expand Up @@ -134,10 +138,27 @@ interface Browser {
* through [Config.browserUrl]; use [stop] to shut the browser down.
*
* A browser process launched by this instance is left running too; [stop] will no longer reach
* it. This instance cannot be used anymore afterwards.
* it, and the shutdown hook will not stop it either. This instance cannot be used anymore
* afterwards.
*
* Its temporary profile (when no [Config.userDataDir] was given) is kept on disk, since the
* browser still runs on it. It is deleted only if [cleanupTemporaryProfile] is called once that
* browser has exited; otherwise whoever shuts the browser down owns the directory, found in
* [Config.userDataDir].
*/
suspend fun detach()

/**
* Deletes the temporary profile this browser created, when no [Config.userDataDir] was given.
*
* A profile passed as [Config.userDataDir] is never deleted. Nor is the temporary one while the
* browser process still runs: this waits a few seconds for it to exit, then gives up and leaves
* the profile in place. Calling it again, or after the profile is gone, does nothing.
*
* [stop] already calls it, and so does the shutdown hook that stops the browsers still running
* when the host process exits (on the JVM). There is usually no need to call it yourself, except
* after [detach], which keeps the profile.
*/
suspend fun cleanupTemporaryProfile()

/**
Expand Down
21 changes: 21 additions & 0 deletions core/src/commonMain/kotlin/dev/kdriver/core/browser/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ class Config(
private var _userDataDir: Path? = null
private var _customDataDir: Boolean = false

/**
* True when [userDataDir] is a temporary profile kdriver created (no directory was given), and it
* has been created already.
*
* Carried over by [copy], like [userDataDir] itself: the browser kdriver launches on such a
* profile deletes it when it stops, whichever copy of the configuration created it. Otherwise a profile
* created before the browser copied its configuration (for instance by reading [userDataDir]
* first) would never be deleted.
*/
internal val createdTemporaryProfile: Boolean
get() = _userDataDir != null && !_customDataDir

private val _browserArgs: MutableList<String> = browserArgs?.toMutableList() ?: mutableListOf()
internal val _extensions: MutableList<Path> = mutableListOf()

Expand All @@ -76,6 +88,12 @@ class Config(
}
}

/**
* The browser profile directory.
*
* When none is given, the first read creates a temporary `kdriver_*` directory, which the browser
* kdriver launches on it deletes when it stops. A directory given here is never deleted.
*/
var userDataDir: Path
get() {
if (_userDataDir == null) {
Expand Down Expand Up @@ -146,6 +164,9 @@ class Config(
*
* The copy is deep where it matters: the argument and extension lists are duplicated, so
* mutating one config never affects the other.
*
* A temporary profile this config already created is shared with the copy, not duplicated: the
* browser kdriver launches on it deletes it when it stops (see [Browser.cleanupTemporaryProfile]).
*/
fun copy(): Config = Config(
// Pass the already-resolved executable so the copy does not re-run the disk search.
Expand Down
Loading
Loading