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 ERR_ACCESS_DENIED for local files on Android SDK 30 #71822
Comments
@ertong
|
@darshankawar |
Replicable when sdk is set to 30. It shows: With sdk set to 29, data shows up properly: flutter doctor -v
|
Probably has to do with giving access to load local files / html with sdk 30. |
Hey, I have the same issue, I can't access any files from documentDirectory inside webview in SDK 30. |
Adding I guess we should make this configurable via Flutter as the Android docs mention security reasons as reasons why the default was set to false. Surprised that this issues has so few likes considering that SDK 30 is a requirement for PlayStore submission now. |
Are all of those necessary for you? For me it works with just webSettings.setAllowFileAccess(true); |
what version of the webview are you using? It didn't works for me... Thanks |
I put Hope it helps you @rvgmartins :) |
While the @Aulig based on your code snippet, I'm assuming you were modifying a previous version of the package? Has anybody been able to get this working on a modern version of the package and if so, what code was modified? |
Hi @alexagat - you're correct, I modified an old version. I didn't notice that it changed in newer versions. I'd assume that you could just add it to the webviewbuilder in the createWebView function something like this: webViewBuilder
.setUsesHybridComposition(usesHybridComposition)
.setDomStorageEnabled(true) // Always enable DOM storage API.
.setJavaScriptCanOpenWindowsAutomatically(
true) // Always allow automatically opening of windows.
.setSupportMultipleWindows(true) // Always support multiple windows.
.setWebChromeClient(webChromeClient)
.setAllowFileAccess(true) // <-- HERE'S MY CHANGE
.setDownloadListener(
downloadListener); // Always use {@link FlutterWebChromeClient} as web Chrome client. But I haven't tested that. Or is that what you already tried Alex? |
@Aulig correct, I tried a number of variations including adding the I'll have to bump the version 1 by 1 to try and identify the specific bump of the |
I see, that's unfortunate. I think I forked off version 2.0.2, which works for me. So you can start your search there if you'd like. Good luck! |
Thank you its worked |
Same issue here |
None of the above solutions are working since the plugin was updated rapidly in the few months and I think the structure had big changes and modifications |
P5 is way to low for this |
adding the line checked with version |
@vgsrivathsan approach also works for me. Will there be an update in the webview plugin to be able to enable this? Currently I have to add the plugin as a local dependency to my Code and add the line from @vgsrivathsan to it. |
Looks like the issue is resolved when using WebView's upstream |
Oh yes, indeed, that works. Thank you @stephg ! |
With this workaround the anchors not work. So o think enable fileaccess is best solution |
You saved my life !!! |
I'm using version 3.0.0 (webview_flutter_android 2.8.3) and have discovered that calling controller.loadUrl() with a file scheme results in the error. However, looking at the source for loadFile(), it sets webView.settings.setAllowFileAccess(true); before calling loadUrl(). This fixes the previous version of loadFile() that did not allow accessing local files from the html page. |
how to use load file method can you please suggest me |
loadFile is a WebViewController method: loadFile( String absoluteFilePath ) -> Future The absoluteFilePath parameter should contain the absolute path to the file as it is stored on the device. For example: /Users/username/Documents/www/index.html. Throws an ArgumentError if the absoluteFilePath does not exist.` `Future _onLoadLocalFileExample(
}` |
I think this will not work on iOS or does it? |
You don't need to change anything |
I just tested the plugin example app on an android emulator running sdk 30 and it works as expected. If anyone is still running into this issue with webview_flutter: ^4.7.0, kindly file a new issue and provide detailed steps to reproduce so we can investigate this. Thank you Screencast.from.04-12-2024.10.31.11.AM.webmflutter doctor -v
|
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Steps to Reproduce
Consider the following code
with dependencies
Run it on android 30 emulator/device.
If you have in build.gradle
everything works as expected (you see WebView with test contents).
But it if you change to
WebView shows net::ERR_ACCESS_DENIED
It looks like this issue comes from changes of default value of https://developer.android.com/reference/android/webkit/WebSettings#setAllowFileAccess(boolean)
We can try to allow changing this setting from flutter widget (which is looks like not good, because setAllowFileAccessFromFileURLs is deprecated).
And/or, maybe better, to implement the recommended mechanism of intercepting url loading (WebViewAssetLoader). In this case, it will be possible to implement file loading from custom scheme in the own code.
The text was updated successfully, but these errors were encountered: