accompanist icon indicating copy to clipboard operation
accompanist copied to clipboard

[WebView] doesn't load local html files

Open saenic opened this issue 3 years ago • 1 comments

Describe the bug

Wenn using the Accompanist WebView Wrapper with a local file url (e.g. file:///data/user/0/com.example.application/files/something/root/imprint.html) it doesn't load and prints out a chrome net::ERR_ACCESS_DENIED.

It works when I use an AndroidView() with a android.webkit.WebView inside

To Reproduce

Steps to reproduce the behavior:

  1. Create a local html file which can be accessed by your app
  2. Use the Accompanist WebView and try to load the file WebView(state = rememberWebViewState("file:///...something.html")
  3. Run the App and open the View
  4. See error

Expected behavior

The WebView Wrapper should load the url like the android.webkit.WebView does

Screenshots?

Environment:

  • Android OS version: Android 9
  • Device: Nokia 8
  • Accompanist version: 0.25.0

saenic avatar Sep 01 '22 12:09 saenic

It works fine for me. I use version 0.26.2-beta. My URL looks slightly different (the file that I access is located in src/main/assets):

file:///android_asset/somefile.html

Then something like this:

 val state = rememberWebViewState(url)
    WebView(
        modifier = Modifier.contentDescription("Document Web View"), state = state
    )

alwa avatar Sep 07 '22 15:09 alwa

Unable to reproduce, I suspect a permissions problem where you are trying to access a file you don't have the rights to. As the comment above shows, that is the correct form to access a file from your assets.

bentrengrove avatar Sep 19 '22 17:09 bentrengrove

It is not a file from assets, it is a file we download and unzip. If it was a permission problem, why does it work using android.webkit.WebView?

I will try it with 0.26 beta when I'm back from vacation.

saenic avatar Sep 19 '22 17:09 saenic

I got it running. We were applying the setting webView.settings.allowFileAccess and I didn't do this in Accompanist WebView Wrapper... so when I use

WebView(
      onCreated = { it.settings.allowFileAccess = true },
      state = rememberWebViewState(imprintUrl)
)

it works

saenic avatar Sep 28 '22 09:09 saenic