[英]Chrome extension: How to modify elements created from an Ajax request in a webpage?
[英]Chrome extension - how to get response of POST request user invoked from a webpage?
我正在尝试创建一个chrome扩展程序,该扩展程序导航到网页,让用户单击网页上发送异步发布请求的按钮,并读取该响应并在扩展程序中使用它。
我从研究中发现的所有内容都告诉我要在扩展本身中创建请求,而我不想这样做,因为我需要Web页面来自行创建请求。
有没有办法在后台脚本上侦听页面本身上的发布请求?
您可以使用chrome.webRequest
和onBeforeRequest
在即将发生请求时chrome.webRequest.onBeforeRequest.addListener(function callback)
。 参数包含HTTP请求数据。 您还需要向侦听器提供requestBody
的extraInfoSpec。
以下是如何使用onBeforeRequest的示例代码片段:
const WEB_REQUEST = chrome.webRequest;
WEB_REQUEST.onBeforeRequest.addListener(
function(details) {
if(details.method == "POST")
console.log(JSON.stringify(details));
},
);
有关POST请求的更多信息,请尝试阅读Chrome扩展程序开发人员指南: https : //developer.chrome.com/extensions/getstarted
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.