How to debug webview remotely?

后端 未结 6 1264
别跟我提以往
别跟我提以往 2021-02-03 22:48

How can I do debug/inspect element of apk webview.
I have tried this but it is helpful only for chrome not for apk.

Please suggest me

6条回答
  •  走了就别回头了
    2021-02-03 23:30

    This is what worked for me, override the method onCreate in MainActivity.java and add this line in the method WebView.setWebContentsDebuggingEnabled(true).

    Here is what my code looks like:

    package com.myapp;
    
    import com.facebook.react.ReactActivity;
    import android.webkit.WebView;
    
    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() {
            super.onCreate();
            //added this line with necessary imports at the top.
            WebView.setWebContentsDebuggingEnabled(true);
        }
    }
    

    Build your code, open your app in phone and go to chrome://inspect , You would see your app listed over there. Click on inspect link.

提交回复
热议问题