如何在不实际打开 DevTools window 的情况下访问 DevTools API?
How to access the DevTools API without actually opening the DevTools window?
documentation 表示 "An instance of the extension's DevTools page is created each time a DevTools window opens. The DevTools page exists for the lifetime of the DevTools window."
但是,Facebook Pixel Helper 设法在没有打开 devtools window 的情况下获取网络信息。
所以,我想知道是否有其他一些 API 或解决方法来访问 DevTools window 中的内容(特别是网络选项卡,Facebook 似乎能够做到这一点) .
chrome.devtools
API不打开devtoolswindow无法使用。 Facebook Pixel Helper 使用 chrome.webRequest
API 获取有关网络请求的信息。此 API 不提供对响应 body 的任何访问权限,因此这不是特别有用。
还有一些更(强大)的方法,不是 FB Pixel Helper extension:
以chrome.debugger
API allows you to do almost anything that the devtools is capable of, including querying the response body, as long as the devtools window is not open. In the following explanation, I assume that you're already attached to the debugger. If you don't know how to do that, see this answer为例。
- 向
chrome.debugger.onEvent
添加侦听器
- 发送
Network.enable
命令开始监听事件。
- 当请求完成时,将触发
onEvent
事件,方法名称设置为Network.responseReceived
。事件参数包括 request/response headers、状态行等。如果您还想获得响应 body,请调用 Network.getResponseBody
命令来获得响应body。
对于其他网络 events/commands,请参阅 debugging protocol specification for network。
- Content scripts can use the
performance.timing
API 查询文档在 (top-level/sub) 帧中的加载时间。
documentation 表示 "An instance of the extension's DevTools page is created each time a DevTools window opens. The DevTools page exists for the lifetime of the DevTools window."
但是,Facebook Pixel Helper 设法在没有打开 devtools window 的情况下获取网络信息。
所以,我想知道是否有其他一些 API 或解决方法来访问 DevTools window 中的内容(特别是网络选项卡,Facebook 似乎能够做到这一点) .
chrome.devtools
API不打开devtoolswindow无法使用。 Facebook Pixel Helper 使用 chrome.webRequest
API 获取有关网络请求的信息。此 API 不提供对响应 body 的任何访问权限,因此这不是特别有用。
还有一些更(强大)的方法,不是 FB Pixel Helper extension:
以
chrome.debugger
API allows you to do almost anything that the devtools is capable of, including querying the response body, as long as the devtools window is not open. In the following explanation, I assume that you're already attached to the debugger. If you don't know how to do that, see this answer为例。- 向
chrome.debugger.onEvent
添加侦听器
- 发送
Network.enable
命令开始监听事件。 - 当请求完成时,将触发
onEvent
事件,方法名称设置为Network.responseReceived
。事件参数包括 request/response headers、状态行等。如果您还想获得响应 body,请调用Network.getResponseBody
命令来获得响应body。
对于其他网络 events/commands,请参阅 debugging protocol specification for network。
- 向
- Content scripts can use the
performance.timing
API 查询文档在 (top-level/sub) 帧中的加载时间。