扩展Chrome DevTool时如何检索请求的发起者? [英] How to retrieve the Initiator of a request when extending Chrome DevTool?

查看:239
本文介绍了扩展Chrome DevTool时如何检索请求的发起者?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个扩展,它需要知道在发出网络请求时谁负责。网络面板的发起者正是我想要的。但我无法使用devtools.network或devtools.panels API获取它。是因为他们根本没有公开这些信息,或者我错过了什么?

你是正确的,因为发起人不是通过devtools扩展API暴露 - 目前,API公开的资源属性仅限于HAR规范中的资源属性,该规范不包括启动器。
您可以使用原始的DevTools协议( https://developers.google.com/chrome -developer-tools / docs / debugger-protocol )来获取DevTools前端的所有数据。请注意,它也暴露给Chrome扩展程序( http://developer.chrome.com/extensions/debugger.html),但DevTools前端打开时无法使用它,因此您将无法在DevTools扩展中访问它。



取决于你想要做什么,实验性时间轴API可能有一定的用处(这个测试显示了这是如何完成的: https://code.google.com/p /chromium/codesearch#chromium/src/third_party/WebKit/LayoutTests/inspector/extensions/extensions-events.html&q=webInspector.timeline&sq=package:chromium&type=cs&l=148 )。与网络中的启动器不同,它不会显示文档中导致静态引用资源加载的位置,但它会为您提供XHR和动态添加到文档中的资源的堆栈跟踪。


I am writing an extension which needs to know who is responsible when a network request is made. The Initiator from the Network Panel is exactly what I want. But I am not able get it using devtools.network or devtools.panels API. Is it because they simply do not expose that information or I am missing something?

解决方案

You are correct in that the initiator is not exposed through devtools extensions API -- currently, the resource properties that the API exposes are limited to that in HAR specification, which does not include initiator. You can use raw DevTools protocol (https://developers.google.com/chrome-developer-tools/docs/debugger-protocol) to get all data available to the DevTools front-end. Note that it is exposed to Chrome extensions as well (http://developer.chrome.com/extensions/debugger.html), but you can't use it when the DevTools front-end is opened, so you won't be able to access it in a DevTools extension.

Depending on what you're trying to do, experimental Timeline API may be of some use (this test shows how this is done: https://code.google.com/p/chromium/codesearch#chromium/src/third_party/WebKit/LayoutTests/inspector/extensions/extensions-events.html&q=webInspector.timeline&sq=package:chromium&type=cs&l=148). Unlike initiators in Network, it won't show you the location in the document that cause a statically referred resource to get loaded, but it will give you stack traces for XHRs and resources that get dynamically added to the document.

这篇关于扩展Chrome DevTool时如何检索请求的发起者?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆