Browser Engine API

The Kotlin surface around GeckoView. Everything browser-engine related flows through these APIs.

Obtaining the runtime

There is exactly one GeckoRuntime per process. Always obtain it via the shared accessor — never construct one directly.

fun getGeckoRuntime(context: Context): GeckoRuntime {
    return geckoRuntime ?: run {
        val settings = GeckoRuntimeSettings.Builder()
            .consoleOutput(true)
            .extensionsProcess(true)
            .build()
        GeckoRuntime.getDefault(context, settings)
            .also { geckoRuntime = it }
    }
}

Creating a session

fun createSession(isPrivate: Boolean): GeckoSession {
    val settings = GeckoSessionSettings.Builder()
        .usePrivateMode(isPrivate)
        .build()
    return GeckoSession(settings)
}

Key delegates

DelegatePurpose
NavigationDelegateLoads, redirects, popup blocking via onNewSession
ContentDelegateTitle, meta, fullscreen requests
ProgressDelegatePage load progress
PermissionDelegateCamera/mic/location prompts

Threading

Main-thread callbacks

GeckoView invokes delegates on the main thread. Hop to a coroutine dispatcher for any real work, and never block the delegate callback.