WebSocket behind WebView in Android Studio

Yeah, it’s me again :slight_smile: Hello community,

I decided to play around with Android Studio and its WebView. On a certain url I have a Live View phoenix app (all working as expected), let’s say example.com. Configurating the WebView, I pass the url


which works well, the site is opening successfully. However, it seems that Live View does not work. I remember I had a similar not working LV when being behind nginx proxy, where

proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;

did the trick. However, I have no idea what to do in the Studio. The question is not fully connected to the Elixir topic, I know, however every through would be highly appreciated. Thank you.

Check webview settings, by default it disables a lot of settings like possibility to run JS. There is also the fact that webview(just like browsers) block mixed content, so ensure that everything is under http or https.

1 Like

the js was enabled, but after a research figured out that WebChromeClient should be created too. For anyone who is/will be wondering the same thing:

mywebView=(WebView) findViewById(R.id.webview);
mywebView.setWebChromeClient(new WebChromeClient());
mywebView.setWebViewClient(new WebViewClient());
WebSettings webSettings=mywebView.getSettings();

Have a nice day

1 Like

After some trial and error, I found that using a GeckoView has several advantages over a Webview, one of which is that state can be preserved when navigating to a different App, Activity or Fragment. One of the bigger downsides is a bigger APK size, due to LibXUL weighing in at about 68 MB…