如何使用Chrome扩展API获取网页的所有HTTP请求

How can I get all HTTP requests of a web page by using Chrome Extension API

本文关键字:HTTP 请求 网页 获取 何使用 Chrome 扩展 API      更新时间:2023-09-26

我知道我可以在DevTool中获得所有HTTP请求,但现在我想在chrome扩展中获得它们。哪一个API可以做这项工作?

您将看到webRequest API带有基于选项卡ID的事件过滤器。

类似的内容(需要"webRequest"权限和"<all_urls>"主机权限):

chrome.webRequest.onBeforeRequest.addListener(
  function(details) {
    // Do something with the details
  },
  {tabId: /* ... */, urls: "<all_urls>"}
);

第页。S.我看到了你关于资源的另一个问题;请注意,您可以按类型进一步筛选请求,例如"stylesheet"

chrome.webRequest很有用,但它不允许您在chrome中读取响应主体。我有一个阅读正文的解决方案:https://stackoverflow.com/a/67390377/1226799