BrowserSession

A browser session. This is the root session created when initially connecting to the browser's debugger.

Such root session doesn't have the most useful APIs because it represents the connection to the browser target.

To interact with more interesting targets, such as pages and workers, you need to first attach to that target, which creates a child session of this session, which offers more APIs:

  • To create a new page/tab, use BrowserSession.newPage and then interact with it through the returned PageSession, which is a child session of the browser session and has many more APIs.

  • If you want to attach to an already existing target, use the BrowserSession.target domain to get information about the target, and then use BrowserSession.attachToTarget. Note that you will only get a plain ChildSession after this. Use one of the converters to convert this session to the proper type depending on the target type you want to interact with. For example, if you're attaching to a worker, use ChildSession.asWorkerSession to get a WorkerSession, which offers the relevant domains for you.

Properties

Link copied to clipboard
abstract val browser: BrowserDomain

The Browser domain defines methods and events for browser managing.

Link copied to clipboard
abstract val fetch: FetchDomain

A domain for letting clients substitute browser's network layer with client code.

Link copied to clipboard
abstract val io: IODomain

Input/Output operations for streams produced by DevTools.

Link copied to clipboard
abstract val memory: MemoryDomain

(undocumented in the protocol definition)

Link copied to clipboard
abstract val security: SecurityDomain

Security

Link copied to clipboard
abstract val storage: StorageDomain

(undocumented in the protocol definition)

Link copied to clipboard

The SystemInfo domain defines methods and events for querying low-level system information.

Link copied to clipboard
abstract val target: TargetDomain

Supports additional targets discovery and allows to attach to them.

Link copied to clipboard

The Tethering domain defines methods and events for browser port binding.

Link copied to clipboard
abstract val tracing: TracingDomain

(undocumented in the protocol definition)

Functions

Link copied to clipboard
abstract suspend fun attachToTarget(targetId: TargetID): ChildSession

Creates a new ChildSession attached to the target with the given targetId. The new session shares the same underlying web socket connection as this BrowserSession.

Link copied to clipboard
abstract suspend fun close()

Closes this session and the underlying web socket connection. This effectively closes all child sessions, because they're based on the same web socket connection.

Link copied to clipboard
abstract suspend fun closeWebSocket()

Closes the underlying web socket connection, effectively closing every session based on the same web socket connection.

Link copied to clipboard
suspend fun BrowserSession.newPage(configure: NewPageConfigBuilder.() -> Unit = {}): PageSession

Creates a new page and attaches to it, then returns the new child PageSession. The underlying web socket connection of this BrowserSession is reused for the new child PageSession.

Link copied to clipboard
abstract fun unsafe(): AllDomainsTarget

Gives access to all domains of the protocol, regardless of the type of this session.

Link copied to clipboard
inline suspend fun <T> BrowserSession.use(block: (BrowserSession) -> T): T

Performs the given operation in this session and closes the web socket connection.