Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View Android webview network requests that occurred on page load in Chrome devtools

If you have a webview open in Android, you can inspect it in Chrome devtools. However, I can't open the devtools first, then open the webview to log network requests that occur on page load. Is there a way to log network requests that occur as soon as the webview loads?

Also, refreshing the page behaves differently from the initial load because the page modifies the URL.

like image 904
Leo Jiang Avatar asked Apr 30 '19 20:04

Leo Jiang


People also ask

How can I view Android WebView in Chrome?

# Open a WebView in DevToolsThe chrome://inspect page displays a list of debug-enabled WebViews on your device. To start debugging, click inspect below the WebView you want to debug. Use DevTools as you would for a remote browser tab.

How do I open popups in WebView?

Overiding shouldOverrideUrlLoading inside WebViewClient implementation will open link in same window. webView. setWebChromeClient(new WebChromeClient() { @Override public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) { WebView newWebView = new WebView(WebpageActivity.

How do I debug a WebView app?

Open an Android WebView in DevTools To display a list of the Android WebViews with debugging turned on that run on your device, go to edge://inspect . To start debugging, under the Android WebView you want to debug, click inspect. Use DevTools in the same way that you use a remote browser tab.

What method is used to load a Web page in the WebView?

The loadUrl() and loadData() methods of Android WebView class are used to load and display web page.


1 Answers

You can intercept various components of WebView communication by implementing your own WebViewClient. A short snippet is below:

webView.webViewClient = object : WebViewClient() {

    override fun shouldInterceptRequest(view: WebView,
        request: WebResourceRequest): WebResourceResponse? {
        // Use the `request` object as needed.
    } 
}

More information regarding the WebViewClient, including other possible overrides, can be found here.

like image 199
Orbit Avatar answered Oct 20 '22 21:10

Orbit