Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple detached webview instances seen in chrome devices while navigating in hybrid android app

We have an hybrid android application. I am trying to navigate from a WebView to a Native context back and forth. Using chrome://inspect/#devices I get to notice that multiple instances of device inspected are detached while one of all would be attached as displayed in chrome. Referring to SO-28254614, now I have not developed the WebView though, but to what I know about our application the WebView are not designed using Cordova and are in JS. An the question that I have are :

  • Why is it so that we see these detached devices on chrome?
  • Could this be a possibility of a leak in Android WebView?
like image 983
Naman Avatar asked Dec 05 '15 07:12

Naman


People also ask

How do I stop WebView from loading on Android?

stopLoading will stop the current load.

Is Android WebView same as Chrome?

No, Chrome for Android is separate from WebView. They're both based on the same code, including a common JavaScript engine and rendering engine.

Which of the following is enabled by default in Android WebView?

The WebView class is an extension of Android's View class that allows you to display web pages as a part of your activity layout. It does not include any features of a fully developed web browser, such as navigation controls or an address bar. All that WebView does, by default, is show a web page.

What is WebView in Chrome?

Android System WebView is a smaller version of Chrome that allows you to open links within the app you're using so you won't have to leave the app. This means that when you click on a link in an app, it will open WebView as if it is the browser built into the app.

How does chromedriver handle multiple webviews in an Android app?

The answer lies in how Chromedriver works. Appium uses Chromedriver for Chrome automation, and Chromedriver handles multiple webviews in a single Android app by treating them as separate windows. What this means is that we have access to them using the built-in Webdriver window commands, like so:

How does Appium handle multiple webviews in an Android app?

Appium uses Chromedriver for Chrome automation, and Chromedriver handles multiple webviews in a single Android app by treating them as separate windows. What this means is that we have access to them using the built-in Webdriver window commands, like so:

Can an android hybrid app have more than one WebView?

It's not very common, but it can happen that an Android hybrid app has not just one but two or more webviews (for example, when advertisements are in one webview and app logic is in another). If you've ever found yourself in this situation, you may have been frustrated when using Appium's context API, specifically with code like this:

What is the difference between Chrome for Android and WebView?

The WebView shipped with Android 4.4 (KitKat) is based on the same code as Chrome for Android version 30. This WebView does not have full feature parity with Chrome for Android and is given the version number 30.0.0.0. The updated WebView shipped with Android 4.4.3 has the version number 33.0.0.0.


1 Answers

So the way these web inspectors work is that they use the RemoteDebug Protocol.

This protocol defines the various messages and commands that are exchanged to let you 'inspect' your pages.

One instance of the inspector can only connect to one client at a time. So assuming that you are switching to and fro web-views and native context, you are basically spawning new webviews for every new context switch.

This would indicate that the previously opened webviews are now 'orphaned' and for all practical purposes detached.

You can try to inform the VM that a webview is no longer in use by calling destroy() on the webview to let the garbage collector know it is no longer required.

Hope this provides a deeper understanding on what is happening behind the scenes.

like image 85
Sunny R Gupta Avatar answered Sep 18 '22 12:09

Sunny R Gupta