Skip to content

shouldOverrideUrlLoading does not seem to get called properly + appreciation post #279

Open
@philippdormann

Description

@philippdormann

First off, thanks so much for this project! 🙏
Saved me lots of time - wish I knew about this before ^^

During implementation of your library, I found a small problem (might as well be on my side)

When registering a WebViewClient() like this, I would normally expect the shouldOverrideUrlLoading function to be called.

wv?.webViewClient = object : WebViewClient() {
    override fun onReceivedError(view: WebView?,request: WebResourceRequest?,error: WebResourceError?) {
        // 
    }
    override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
        Log.d("LOGGER", "url-triggered")
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            if (request != null) {
                val u = request.url.toString()
                if(u.contains("keyword")) {
                    // website should not load, custom handler
                    return true
                }
            }
        }
    }
    override fun onPageFinished(view: WebView?, url: String?) {
        super.onPageFinished(view, url)
    }
    return super.shouldOverrideUrlLoading(view, request)
}

Expected

  • when loading a new url (calling wv?.loadUrl()) the shouldOverrideUrlLoading function should be called
  • as a result
    • url-triggered should be logged
    • the url should not be loaded, because of the return true

Actual

  • url gets loaded
  • shouldOverrideUrlLoading is not called; noting is logged

Possibility to Avoid this / get the expected behaviour

I would not call this a clean approach, but it works 🙄

  • override onPageStarted
  • check url
  • wv?.stopLoading()
  • wv?.onBackPressed()

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions