Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting WebChromeClient and WebViewClient #162

Open
ArabAgile opened this issue Dec 16, 2018 · 1 comment
Open

Setting WebChromeClient and WebViewClient #162

ArabAgile opened this issue Dec 16, 2018 · 1 comment

Comments

@ArabAgile
Copy link

I need to inject cookies and headers in each request. How possible it's using FinestWebView?

Also, I need to do something in shouldOverrideUrlLoading, how to achieve this?

@Cililing
Copy link

Cililing commented Apr 9, 2019

About Cookies - you can do it via CookieManager. For example:

fun setWebViewSession(url: String, onSessionSet: (() -> Unit)?) {
        doAsync {
            // Refresh login data
            ...
            // Build and execute request
            ...
            val response = httpClient.newCall(request).execute()

            // Obtain and sync cookies
            val cookies = response.headers().values("Set-Cookie")

            CookieSyncManager.createInstance(application)
            CookieSyncManager.getInstance().startSync()

            val cookieManager = CookieManager.getInstance()
            cookieManager.removeAllCookie()

            cookies.forEach {
                cookieManager.setCookie(URL(url).host, it)
            }

            CookieSyncManager.getInstance().sync()

            onSessionSet?.invoke()
        }
    }

This code snipped is about loggin user, that's why I make a request before setting cookies. For your purposes it should look fimilar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants