从嵌入式 Android WebView 记录 HTTP 请求的开始和结束
我正在寻找一种方法来记录嵌入式网络视图发出的请求和开始/结束时间。到目前为止,除了 root 手机并运行 tcpdump 之外,我找不到其他方法来做到这一点。这对我有用,但我需要在现场运行它,所以这并不是真正可行。有很多方法可以记录 URL 和开始时间,但我看不到结束(或者,奖金,完整的响应元数据)。
如果我可以包装当前请求,shouldLoadResource 就可以工作,但我必须自己使用 HTTP 支持来获取它,以便批量返回它,因为没有足够的 API 公开来完全转发到内部请求。 (出于多种原因,我不想这样做,包括设备上的 webview 不使用与 HTTP 类相同的网络堆栈,并且因为它会改变子资源的时间。)
我一直在尝试找到打开 chromium_net 调试标志的方法来执行此操作,但我无法弄清楚如何在 WebView 或系统属性的上下文中执行此操作。
我真的不想发布我自己的网络核心来做到这一点,但如果需要必须......
I'm looking for a way to log the requests and start/end times made by an embedded webview. I'm not able to find a way to do it so far other than rooting the phone and running tcpdump. That works for me, but I need to run this in the field, so that's not really viable. There are lots of ways to log the URL and start time, but I can't see the finish (or, bonus, the full response metadata).
shouldLoadResource could work if I could wrap the current request, but I'd have to fetch it myself with HTTP support in order to return it en masse, because there isn't enough API exposed to fully forward to the inner request. (I don't want to do that for a number of reasons, including that webview on devices doesn't use the same network stack as the HTTP classes, and because it will change the timing of subresources.)
I've been trying to find ways to turn on chromium_net debug flags to do this, but I can't figure out how do do that in the context of the WebView or system properties.
I would really rather not ship my own webcore to do this, but if needs must...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
重写方法
shouldInterceptRequest()
override method
shouldInterceptRequest()
在这种情况下,您还可以添加 WebViewClient (请参阅 http://developer.android .com/reference/android/webkit/WebViewClient.html)。看起来像这样
请注意,shouldOverrideUrlLoading 和 onPageFinished 仅针对主框架调用 - 它们不会针对 iframe 或框架集调用。但这应该可以满足您的需要。
In that case, you could also add a WebViewClient (see http://developer.android.com/reference/android/webkit/WebViewClient.html). Which would look something like
Note that both shouldOverrideUrlLoading and onPageFinished are only called only for the main frame - they will not be called for iframes or framesets. But this should give you what you need.