All Downloads are FREE. Search and download functionalities are using the official Maven repository.

desktopMain.com.multiplatform.webview.web.CefRequestExt.kt Maven / Gradle / Ivy

There is a newer version: 1.9.40
Show newest version
package com.multiplatform.webview.web

import com.multiplatform.webview.setting.WebSettings
import dev.datlag.kcef.KCEFResourceRequestHandler
import org.cef.browser.CefBrowser
import org.cef.browser.CefFrame
import org.cef.browser.CefRequestContext
import org.cef.network.CefRequest

internal fun createModifiedRequestContext(settings: WebSettings): CefRequestContext {
    return CefRequestContext.createContext { browser, frame, request, isNavigation, isDownload, requestInitiator, disableDefaultHandling ->
        object : KCEFResourceRequestHandler(
            getGlobalDefaultHandler(browser, frame, request, isNavigation, isDownload, requestInitiator, disableDefaultHandling),
        ) {
            override fun onBeforeResourceLoad(
                browser: CefBrowser?,
                frame: CefFrame?,
                request: CefRequest?,
            ): Boolean {
                if (request != null) {
                    settings.customUserAgentString?.let(request::setUserAgentString)
                }
                return super.onBeforeResourceLoad(browser, frame, request)
            }
        }
    }
}

internal fun CefRequest.setUserAgentString(userAgent: String) {
    setHeaderByName("User-Agent", userAgent, true)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy