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

[WebView] window.location.reload() broken by shouldOverrideUrlLoading #1335

Closed
matthewmjohnson opened this issue Sep 15, 2022 · 0 comments · Fixed by #1344
Closed

[WebView] window.location.reload() broken by shouldOverrideUrlLoading #1335

matthewmjohnson opened this issue Sep 15, 2022 · 0 comments · Fixed by #1344
Assignees

Comments

@matthewmjohnson
Copy link

matthewmjohnson commented Sep 15, 2022

AccompanistWebViewClient overrides shouldOverrideUrlLoading with

 override fun shouldOverrideUrlLoading(
        view: WebView?,
        request: WebResourceRequest?
    ): Boolean {
        // Override all url loads to make the single source of truth
        // of the URL the state holder Url
        request?.let {
            state.content = state.content.withUrl(it.url.toString())
        }
        return true
    }

Returning true ensures that the load is always cancelled here though since it's setting state.content it will normally result in the URL being loaded. However

                if (url.isNotEmpty() && url != view.url) {
                    view.loadUrl(url, content.additionalHttpHeaders.toMutableMap())
                }

in com.google.accompanist.web.WebView explicitly skips the load if the URL has not changed. This means that javascript like window.location.reload() will not reload the page.

To Reproduce

I've attached AccompanistTest.zip with a sample project demonstrating the issue.

This loads a local HTML page with a single button that should reload the page with window.location.reload(). On page load, ********PAGE LOADED******** should be written to console and is logged to logcat.

This only shows up on initial page load though, the button doesn't do anything.

Uncommenting the inelegant lines 50-52 in the sample project's MainActivity fixes the issue by avoiding the AccompanistWebViewClient.shouldOverrideUrlLoading call if the URL matches the existing URL:

                                if (view?.url == request?.url.toString()) {
                                    return false
                                }

Expected behavior

Page should reload on window.location.reload() and other similar calls that normally cause pages to reload.

Environment:

  • Android OS version: Android 13
  • Device: P6Pro
  • Accompanist version: 0.25.1
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

Successfully merging a pull request may close this issue.

3 participants