Skip to content

Commit

Permalink
Rename ChromeBrowserSession -> BrowserSession to align with others
Browse files Browse the repository at this point in the history
Resolves:
#254
  • Loading branch information
joffrey-bion committed May 15, 2023
1 parent e457939 commit eb95a11
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 31 deletions.
18 changes: 9 additions & 9 deletions api/chrome-devtools-kotlin.api
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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).
*
Expand All @@ -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,
Expand All @@ -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).
*
Expand All @@ -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,
Expand Down Expand Up @@ -136,7 +136,7 @@ suspend fun PageSession.childPages(): List<TargetInfo> {
*
* Note: This effectively closes every session based on the same web socket connection.
*/
suspend inline fun <T> ChromeBrowserSession.use(block: (ChromeBrowserSession) -> T): T {
suspend inline fun <T> BrowserSession.use(block: (BrowserSession) -> T): T {
try {
return block(this)
} finally {
Expand Down Expand Up @@ -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<Map<TargetID, TargetInfo>> {
suspend fun BrowserSession.watchTargetsIn(coroutineScope: CoroutineScope): StateFlow<Map<TargetID, TargetInfo>> {
val targetsFlow = MutableStateFlow(emptyMap<TargetID, TargetInfo>())

target.events().onEach { targetsFlow.value = targetsFlow.value.updatedBy(it) }.launchIn(coroutineScope)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit eb95a11

Please sign in to comment.