Skip to content

Commit

Permalink
Injecting launch arguments to web page (#2223)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-zaitsev authored Jan 2, 2025
1 parent 266c9a8 commit c4b0de9
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions maestro-client/src/main/java/maestro/drivers/WebDriver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class WebDriver(val isStudio: Boolean) : Driver {
private var seleniumDriver: org.openqa.selenium.WebDriver? = null
private var maestroWebScript: String? = null
private var lastSeenWindowHandles = setOf<String>()
private var injectedArguments: Map<String, Any> = emptyMap()

private var webScreenRecorder: WebScreenRecorder? = null

Expand Down Expand Up @@ -102,6 +103,11 @@ class WebDriver(val isStudio: Boolean) : Driver {

try {
executor.executeScript("$maestroWebScript")

injectedArguments.forEach { (key, value) ->
executor.executeScript("$key = '$value'")
}

Thread.sleep(100)
return executor.executeScript(js)
} catch (e: Exception) {
Expand Down Expand Up @@ -137,6 +143,8 @@ class WebDriver(val isStudio: Boolean) : Driver {
}

override fun close() {
injectedArguments = emptyMap()

try {
seleniumDriver?.quit()
webScreenRecorder?.close()
Expand Down Expand Up @@ -169,6 +177,8 @@ class WebDriver(val isStudio: Boolean) : Driver {
launchArguments: Map<String, Any>,
sessionId: UUID?,
) {
injectedArguments = injectedArguments + launchArguments

open()
val driver = ensureOpen()

Expand Down

0 comments on commit c4b0de9

Please sign in to comment.