本文介绍了如何拦截网页资源的所有网络请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

网页加载包括JavaScript,CSS和许多其他类型的文件之类的资源。我想用Chromium代码拦截所有这些资源的网络请求。有什么方法可以做到这一点?

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?

推荐答案

使用

Stetho 是适用于Android应用程序的复杂调试桥。启用后,开发人员可以访问Chrome桌面浏览器本地提供的Chrome开发者工具功能。

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.

完成设置说明后,只需启动应用,然后将浏览器指向 chrome:// inspect 。单击检查按钮开始。

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

设置

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'

或:

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

取决于您的情况

也将以下代码放在Application类中:

also put below code in your Application class:

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

还要确保您的 MyApplication 类已注册到您的 AndroidManifest.xml 文件

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>

这篇关于如何拦截网页资源的所有网络请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 15:09
查看更多