How to intercept all the network requests of resources for a Web Page?

时光总嘲笑我的痴心妄想 提交于 2019-12-08 10:44:25

问题


A webpage loading includes resources like JavaScript, CSS and many other kinds of files. I want to intercept all those network request of resources in Chromium code. Is there any way to do this?


回答1:


Use Stetho

Stetho is a sophisticated debug bridge for Android applications. When enabled, developers have access to the Chrome Developer Tools feature natively part of the Chrome desktop browser.

Once you complete the set-up instructions, just start your app and point your browser to chrome://inspect . Click the "Inspect" button to begin.

Set-up

implementation 'com.facebook.stetho:stetho:1.5.1'

you may also wish to use one of the network helpers:

implementation 'com.facebook.stetho:stetho-okhttp3:1.5.1'

or:

implementation 'com.facebook.stetho:stetho-urlconnection:1.5.1'

depends upon your case

also put below code in your Application class:

public class MyApplication extends Application {
  public void onCreate() {
    super.onCreate();
    Stetho.initializeWithDefaults(this);
  }
}

Also ensure that your MyApplication class is registered in your AndroidManifest.xml file

<manifest
        xmlns:android="http://schemas.android.com/apk/res/android"
        ...>
        <application
                android:name="MyApplication"
                ...>
         </application>
</manifest> 


来源:https://stackoverflow.com/questions/55373682/how-to-intercept-all-the-network-requests-of-resources-for-a-web-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!