Flutter Webview two way communication with Javascript

Here is an example of communication from Javascript code to flutter. In Flutter build your WebView like : WebView( initialUrl: url, javascriptMode: JavascriptMode.unrestricted, javascriptChannels: Set.from([ JavascriptChannel( name: ‘Print’, onMessageReceived: (JavascriptMessage message) { //This is where you receive message from //javascript code and handle in Flutter/Dart //like here, the message is just being printed //in Run/LogCat … Read more

Android Webview POST

Two ways to load post response in webview: webview.loadData(): Like what you have posted in your solution. But “content loaded through this mechanism does not have the ability to load content from the network”. webview.postUrl(): Use this if post response needs to load content from the network. (NOTE: only accessible from api-level 5, which means … Read more

Android WebView JellyBean -> Should not happen: no rect-based-test nodes found

The issue occurs because in some scenarios WebView fails to notice that its visible rect has changed, so as far as webkit is concerned the page is still not visible. Thus all touches fall outside of the window, and get rejected. The cleanest fix is when you know the visibility of your WebView has changed … Read more

Caching in Android webview

Don’t use these: viewer.getSettings().setAppCacheMaxSize(1024*1024*8); viewer.getSettings().setAppCachePath(“/data/data/com.your.package.appname/cache”‌​); viewer.getSettings().setAppCacheEnabled(true); These have nothing to do with the default webview internal cache. Appcache is an entirely different feature mean to make you able to run the website w/o an internet connection. It does not work that great and probably you do not want to use it. With setting this: viewer.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT) … Read more

How can I see Javascript errors in WebView in an Android app?

You can actually receive the console messages from a WebView, which would allow you to catch the errors that it throws. To do so: Enable JavaScript on your WebView Set a WebChromeClient Override onConsoleMessage Example: final WebView webView = (WebView) findViewById(R.id.webview_terms_conditions); WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); webView.setWebChromeClient(new WebChromeClient() { @Override public boolean onConsoleMessage(ConsoleMessage consoleMessage) { … Read more

WebView “flashing” with white background if hardware acceleration is enabled (Android 3.0+)

I found the most effective fix for this, first mentioned here, was to set a transparent background color after the layout has been inflated: webView.setBackgroundColor(Color.argb(1, 0, 0, 0)); Yes, it’s a total hack, but it’s the only solution I’ve found to work well without disabling hardware acceleration. Note that this does not work through setting … Read more

Android WebView inside ScrollView scrolls only scrollview

Here is the solution. Found online. I have subclassed WebView and i’m using the requestDisallowInterceptTouchEvent(true); method to allow my webview to handle the scroll event. TouchyWebView.java package com.mypackage.common.custom.android.widgets public class TouchyWebView extends WebView { public TouchyWebView(Context context) { super(context); } public TouchyWebView(Context context, AttributeSet attrs) { super(context, attrs); } public TouchyWebView(Context context, AttributeSet attrs, int … Read more

Chrome App webview and touch scroll propagation

I’m going to assume a couple things here: Styling a Chrome app is similar to styling a webpage. Your current scrolling solution relies on using overflow:hidden and using JavaScript only to scroll. I fixed something similar once for a page. Its strange but I learned that for touch devices, a scrollbar is invisible unless the … Read more

How to make a Scroll Listener for WebView in Android

Something like: public class ObservableWebView extends WebView { private OnScrollChangedCallback mOnScrollChangedCallback; public ObservableWebView(final Context context) { super(context); } public ObservableWebView(final Context context, final AttributeSet attrs) { super(context, attrs); } public ObservableWebView(final Context context, final AttributeSet attrs, final int defStyle) { super(context, attrs, defStyle); } @Override protected void onScrollChanged(final int l, final int t, final int … Read more