diff --git a/api/chrome-devtools-kotlin.api b/api/chrome-devtools-kotlin.api index 07cfa597..19b486fe 100644 --- a/api/chrome-devtools-kotlin.api +++ b/api/chrome-devtools-kotlin.api @@ -45298,14 +45298,14 @@ public abstract interface class org/hildan/chrome/devtools/targets/ChildSession public abstract fun close (ZLkotlin/coroutines/Continuation;)Ljava/lang/Object; public abstract fun detach (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public abstract fun getMetaData ()Lorg/hildan/chrome/devtools/targets/SessionMetaData; - public abstract fun getParent ()Lorg/hildan/chrome/devtools/targets/ChromeBrowserSession; + public abstract fun getParent ()Lorg/hildan/chrome/devtools/targets/BrowserSession; } public final class org/hildan/chrome/devtools/targets/ChildSession$DefaultImpls { public static synthetic fun close$default (Lorg/hildan/chrome/devtools/targets/ChildSession;ZLkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; } -public abstract interface class org/hildan/chrome/devtools/targets/ChromeBrowserSession : org/hildan/chrome/devtools/targets/BrowserTarget, org/hildan/chrome/devtools/targets/ChromeSession { +public abstract interface class org/hildan/chrome/devtools/targets/BrowserSession : org/hildan/chrome/devtools/targets/BrowserTarget, org/hildan/chrome/devtools/targets/ChromeSession { public abstract fun attachToTarget (Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public abstract fun close (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } @@ -45400,19 +45400,19 @@ public final class org/hildan/chrome/devtools/targets/SharedWorkerTarget$Compani } public final class org/hildan/chrome/devtools/targets/TargetExtensionsKt { - public static final fun attachToNewPage (Lorg/hildan/chrome/devtools/targets/ChromeBrowserSession;Ljava/lang/String;ZIIZLkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun attachToNewPage$default (Lorg/hildan/chrome/devtools/targets/ChromeBrowserSession;Ljava/lang/String;ZIIZLkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun attachToNewPageAndAwaitPageLoad (Lorg/hildan/chrome/devtools/targets/ChromeBrowserSession;Ljava/lang/String;ZIIZLkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun attachToNewPageAndAwaitPageLoad$default (Lorg/hildan/chrome/devtools/targets/ChromeBrowserSession;Ljava/lang/String;ZIIZLkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun attachToPage (Lorg/hildan/chrome/devtools/targets/ChromeBrowserSession;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun attachToNewPage (Lorg/hildan/chrome/devtools/targets/BrowserSession;Ljava/lang/String;ZIIZLkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static synthetic fun attachToNewPage$default (Lorg/hildan/chrome/devtools/targets/BrowserSession;Ljava/lang/String;ZIIZLkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; + public static final fun attachToNewPageAndAwaitPageLoad (Lorg/hildan/chrome/devtools/targets/BrowserSession;Ljava/lang/String;ZIIZLkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static synthetic fun attachToNewPageAndAwaitPageLoad$default (Lorg/hildan/chrome/devtools/targets/BrowserSession;Ljava/lang/String;ZIIZLkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; + public static final fun attachToPage (Lorg/hildan/chrome/devtools/targets/BrowserSession;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun childPages (Lorg/hildan/chrome/devtools/sessions/PageSession;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun getTargetInfo (Lorg/hildan/chrome/devtools/sessions/PageSession;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun navigateAndAwaitPageLoad (Lorg/hildan/chrome/devtools/sessions/PageSession;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun navigateAndAwaitPageLoad (Lorg/hildan/chrome/devtools/sessions/PageSession;Lorg/hildan/chrome/devtools/domains/page/NavigateRequest;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static synthetic fun navigateAndAwaitPageLoad$default (Lorg/hildan/chrome/devtools/sessions/PageSession;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; public static final fun use (Lorg/hildan/chrome/devtools/sessions/PageSession;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun use (Lorg/hildan/chrome/devtools/targets/ChromeBrowserSession;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun watchTargetsIn (Lorg/hildan/chrome/devtools/targets/ChromeBrowserSession;Lkotlinx/coroutines/CoroutineScope;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun use (Lorg/hildan/chrome/devtools/targets/BrowserSession;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun watchTargetsIn (Lorg/hildan/chrome/devtools/targets/BrowserSession;Lkotlinx/coroutines/CoroutineScope;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } public abstract interface class org/hildan/chrome/devtools/targets/WorkerTarget { diff --git a/src/commonMain/kotlin/org/hildan/chrome/devtools/protocol/ChromeDPClient.kt b/src/commonMain/kotlin/org/hildan/chrome/devtools/protocol/ChromeDPClient.kt index d3066408..570c0fb5 100644 --- a/src/commonMain/kotlin/org/hildan/chrome/devtools/protocol/ChromeDPClient.kt +++ b/src/commonMain/kotlin/org/hildan/chrome/devtools/protocol/ChromeDPClient.kt @@ -127,21 +127,21 @@ class ChromeDPClient( * Opens a web socket connection to interact with the browser. * * This method attaches to the default browser target, which creates a root session without session ID. - * The returned [ChromeBrowserSession] thus only provides a limited subset of the possible operations (only the + * The returned [BrowserSession] thus only provides a limited subset of the possible operations (only the * ones applicable to the browser itself). * - * To attach to a specific target (such as a web page), call [ChromeBrowserSession.attachToPage], - * [ChromeBrowserSession.attachToNewPage][org.hildan.chrome.devtools.targets.attachToNewPage], or similar + * To attach to a specific target (such as a web page), call [BrowserSession.attachToPage], + * [BrowserSession.attachToNewPage][org.hildan.chrome.devtools.targets.attachToNewPage], or similar * functions. This creates a nested session with a type corresponding to the target type, which provides access to * another set of domains. Such nested sessions use the same underlying web socket connection as the initial * browser session returned here. * * Note that the caller of this method is responsible for closing the web socket after use by calling - * [ChromeBrowserSession.close], or indirectly by calling `use()` on the browser session. + * [BrowserSession.close], or indirectly by calling `use()` on the browser session. * Calling [close()][PageSession.close] or `use()` on a derived [PageSession] doesn't close the * underlying web socket connection, to avoid undesirable interactions between nested sessions. */ - suspend fun webSocket(): ChromeBrowserSession { + suspend fun webSocket(): BrowserSession { val browserDebuggerUrl = version().webSocketDebuggerUrl return httpClient.chromeWebSocket(browserDebuggerUrl) } @@ -217,11 +217,11 @@ data class ChromeDPTarget( * This [HttpClient] must have the [WebSockets] plugin installed, as well as the [ContentNegotiation] plugin * with Kotlinx Serialization JSON. * - * The returned [ChromeBrowserSession] only provides a limited subset of the possible operations, because it is + * The returned [BrowserSession] only provides a limited subset of the possible operations, because it is * attached to the default *browser* target, not a *page* target. * To attach to a specific target using the same underlying web socket connection, call - * [ChromeBrowserSession.attachToPage] or - * [ChromeBrowserSession.attachToNewPage][org.hildan.chrome.devtools.targets.attachToNewPage]. + * [BrowserSession.attachToPage] or + * [BrowserSession.attachToNewPage][org.hildan.chrome.devtools.targets.attachToNewPage]. */ -suspend fun HttpClient.chromeWebSocket(webSocketDebuggerUrl: String): ChromeBrowserSession = +suspend fun HttpClient.chromeWebSocket(webSocketDebuggerUrl: String): BrowserSession = webSocketSession(webSocketDebuggerUrl).chromeDp().withSession(sessionId = null).toBrowserSession() diff --git a/src/commonMain/kotlin/org/hildan/chrome/devtools/targets/Compat.kt b/src/commonMain/kotlin/org/hildan/chrome/devtools/targets/Compat.kt index e4f04604..ec8a5fd5 100644 --- a/src/commonMain/kotlin/org/hildan/chrome/devtools/targets/Compat.kt +++ b/src/commonMain/kotlin/org/hildan/chrome/devtools/targets/Compat.kt @@ -30,3 +30,12 @@ typealias RenderFrameTarget = PageTarget ), ) typealias ChromePageMetaData = SessionMetaData + +@Deprecated( + message = "Renamed BrowserSession", + replaceWith = ReplaceWith( + expression = "BrowserSession", + imports = ["org.hildan.chrome.devtools.targets.BrowserSession"], + ), +) +typealias ChromeBrowserSession = BrowserSession diff --git a/src/commonMain/kotlin/org/hildan/chrome/devtools/targets/InternalTargetSessions.kt b/src/commonMain/kotlin/org/hildan/chrome/devtools/targets/InternalTargetSessions.kt index cd4752dd..655a62fe 100644 --- a/src/commonMain/kotlin/org/hildan/chrome/devtools/targets/InternalTargetSessions.kt +++ b/src/commonMain/kotlin/org/hildan/chrome/devtools/targets/InternalTargetSessions.kt @@ -6,7 +6,7 @@ import org.hildan.chrome.devtools.protocol.ChromeDPSession import org.hildan.chrome.devtools.protocol.ExperimentalChromeApi import org.hildan.chrome.devtools.protocol.withSession -internal fun ChromeDPSession.toBrowserSession(): ChromeBrowserSession = BrowserSessionImpl(this) +internal fun ChromeDPSession.toBrowserSession(): BrowserSession = BrowserSessionImpl(this) private sealed class AbstractTargetSession( protected val session: ChromeDPSession, @@ -23,7 +23,7 @@ private sealed class AbstractTargetSession( private class BrowserSessionImpl( session: ChromeDPSession, targetImplementation: UberTarget = UberTarget(session), -) : AbstractTargetSession(session, targetImplementation), ChromeBrowserSession, BrowserTarget by targetImplementation { +) : AbstractTargetSession(session, targetImplementation), BrowserSession, BrowserTarget by targetImplementation { @OptIn(ExperimentalChromeApi::class) override suspend fun attachToTarget(targetId: TargetID): ChildSession { @@ -45,7 +45,7 @@ private class BrowserSessionImpl( private class ChildSessionImpl( session: ChromeDPSession, - override val parent: ChromeBrowserSession, + override val parent: BrowserSession, override val metaData: MetaData, targetImplementation: UberTarget = UberTarget(session), ) : AbstractTargetSession(session, targetImplementation), diff --git a/src/commonMain/kotlin/org/hildan/chrome/devtools/targets/TargetExtensions.kt b/src/commonMain/kotlin/org/hildan/chrome/devtools/targets/TargetExtensions.kt index b76eb634..e6db680b 100644 --- a/src/commonMain/kotlin/org/hildan/chrome/devtools/targets/TargetExtensions.kt +++ b/src/commonMain/kotlin/org/hildan/chrome/devtools/targets/TargetExtensions.kt @@ -16,12 +16,12 @@ import org.hildan.chrome.devtools.sessions.* imports = ["org.hildan.chrome.devtools.sessions.asPageSession"], ), ) -suspend fun ChromeBrowserSession.attachToPage(targetId: TargetID): PageSession = +suspend fun BrowserSession.attachToPage(targetId: TargetID): PageSession = attachToTarget(targetId).asPageSession() /** * Creates and attaches to a new page (tab) initially navigated to the given [url]. - * The underlying web socket connection of this [ChromeBrowserSession] is reused for the new [PageSession]. + * The underlying web socket connection of this [BrowserSession] is reused for the new [PageSession]. * * If [incognito] is true, the new target is created in a separate browser context (think of it as incognito window). * @@ -30,7 +30,7 @@ suspend fun ChromeBrowserSession.attachToPage(targetId: TargetID): PageSession = * If [background] is true, the new tab will be created in the background (Chrome only). */ @OptIn(ExperimentalChromeApi::class) -suspend fun ChromeBrowserSession.attachToNewPage( +suspend fun BrowserSession.attachToNewPage( url: String = "about:blank", incognito: Boolean = true, width: Int = 1024, @@ -55,7 +55,7 @@ suspend fun ChromeBrowserSession.attachToNewPage( /** * Creates and attaches to a new page (tab) initially navigated to the given [url]. * Suspends until the `frameStoppedLoading` event is fired. - * The underlying web socket connection of this [ChromeBrowserSession] is reused for the new [PageSession]. + * The underlying web socket connection of this [BrowserSession] is reused for the new [PageSession]. * * If [incognito] is true, the new target is created in a separate browser context (think of it as incognito window). * @@ -66,7 +66,7 @@ suspend fun ChromeBrowserSession.attachToNewPage( * This function throws [NavigationFailed] if the navigation response has an error, instead of waiting forever for an * event that will never come. */ -suspend fun ChromeBrowserSession.attachToNewPageAndAwaitPageLoad( +suspend fun BrowserSession.attachToNewPageAndAwaitPageLoad( url: String, incognito: Boolean = true, width: Int = 1024, @@ -136,7 +136,7 @@ suspend fun PageSession.childPages(): List { * * Note: This effectively closes every session based on the same web socket connection. */ -suspend inline fun ChromeBrowserSession.use(block: (ChromeBrowserSession) -> T): T { +suspend inline fun BrowserSession.use(block: (BrowserSession) -> T): T { try { return block(this) } finally { @@ -167,7 +167,7 @@ suspend fun PageSession.getTargetInfo(): TargetInfo = target.getTargetInfo().tar /** * Watches the available targets in this browser. */ -suspend fun ChromeBrowserSession.watchTargetsIn(coroutineScope: CoroutineScope): StateFlow> { +suspend fun BrowserSession.watchTargetsIn(coroutineScope: CoroutineScope): StateFlow> { val targetsFlow = MutableStateFlow(emptyMap()) target.events().onEach { targetsFlow.value = targetsFlow.value.updatedBy(it) }.launchIn(coroutineScope) diff --git a/src/commonMain/kotlin/org/hildan/chrome/devtools/targets/TargetSessions.kt b/src/commonMain/kotlin/org/hildan/chrome/devtools/targets/TargetSessions.kt index e929ec5a..36720878 100644 --- a/src/commonMain/kotlin/org/hildan/chrome/devtools/targets/TargetSessions.kt +++ b/src/commonMain/kotlin/org/hildan/chrome/devtools/targets/TargetSessions.kt @@ -30,11 +30,11 @@ interface ChromeSession { * * The root browser session doesn't have a session ID. */ -interface ChromeBrowserSession : ChromeSession, BrowserTarget { +interface BrowserSession : ChromeSession, BrowserTarget { /** * Creates a new [ChildSession] attached to the target with the given [targetId]. - * The new session shares the same underlying web socket connection as this [ChromeBrowserSession]. + * The new session shares the same underlying web socket connection as this [BrowserSession]. */ suspend fun attachToTarget(targetId: TargetID): ChildSession @@ -79,7 +79,7 @@ interface ChildSession : ChromeSession { * [session hierarchy section](https://github.com/aslushnikov/getting-started-with-cdp/blob/master/README.md#session-hierarchy) * in the "getting started" guide. */ - val parent: ChromeBrowserSession + val parent: BrowserSession /** * Info about this session and its underlying target.