问题
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