How to debug webview remotely?

How can I make the debug / inspect element a webview apk.
I tried this , but it is only useful for Chrome, not for APK.

Please offer me

+14
source share
6 answers

Try the following:

  • Enable developer options on the device (Settings → About phone → Press 7 times on the build number)
  • Turn on developer options and enable USB debugging (in developer settings)
  • Add this line to your own application class or to the Activity where the webview is loaded

    // if your build is in debug mode, enable web view validation

    if (0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE)) {
        WebView.setWebContentsDebuggingEnabled(true);
    }
    
  • Chrome chrome://inspect/#devices, .

  • , , .

.

+27

, , onCreate MainActivity.java WebView.setWebContentsDebuggingEnabled(true).

:

package com.myapp;

import com.facebook.react.ReactActivity;
import android.webkit.WebView;
import android.os.Bundle;

public class MainActivity extends ReactActivity {

    /**
     * Returns the name of the main component registered from JavaScript.
     * This is used to schedule rendering of the component.
     */
    @Override
    protected String getMainComponentName() {
        return "myapp";
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //added this line with necessary imports at the top.
        WebView.setWebContentsDebuggingEnabled(true);
    }
}

, chrome://inspect. . .

+2
+1

- Android, WebView.setWebContentsDebuggingEnabled(true) WebviewActivity

chrome:///# . . ! https://developers.google.com/web/tools/chrome-devtools/remote-debugging/webviews

0

Source: https://habr.com/ru/post/1527858/


All Articles