修改Chrome扩展程序中的HTTP响应 [英] Modify HTTP responses from a Chrome extension
问题描述
是否可以创建一个修改HTTP响应实体的Chrome扩展?
我已经查看了 Chrome扩展API ,但我还没有发现任何可以做到这一点的内容。
通常,不能使用标准的Chrome扩展API更改HTTP请求的响应正文。
此功能正在 104058:WebRequest API:允许扩展程序编辑响应主体<一>。 如果您想编辑已知 在其他情况下,您可以使用 Is it possible to create a Chrome extension that modifies HTTP response bodies? I have looked in the Chrome Extension APIs, but I haven't found anything to do this. In general, you cannot change the response body of a HTTP request using the standard Chrome extension APIs. This feature is being requested at 104058: WebRequest API: allow extension to edit response body. Star the issue to get notified of updates. If you want to edit the response body for a known In other cases, you can use the 这篇关于修改Chrome扩展程序中的HTTP响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
XMLHttpRequest
的响应正文, 注入代码通过内容脚本来重写默认的 XMLHttpRequest
构造函数,并使用自定义(全功能)构造函数来重写响应,然后触发真实事件。确保您的XMLHttpRequest对象完全符合Chrome内置的 XMLHttpRequest
对象,否则AJAX网站会崩溃。
chrome.webRequest
或 chrome.declarativeWebRequest
API将请求重定向到 data:
-URI。与XHR方法不同,您不会得到请求的原始内容。实际上,请求永远不会到达服务器,因为重定向只能在发送实际请求之前完成。如果您重定向 main_frame
请求,用户将看到 data:
-URI,而不是请求的URL。 / p> XMLHttpRequest
, inject code via a content script to override the default XMLHttpRequest
constructor with a custom (full-featured) one that rewrites the response before triggering the real event. Make sure that your XMLHttpRequest object is fully compliant with Chrome's built-in XMLHttpRequest
object, or AJAX-heavy sites will break.chrome.webRequest
or chrome.declarativeWebRequest
APIs to redirect the request to a data:
-URI. Unlike the XHR-approach, you won't get the original contents of the request. Actually, the request will never hit the server because redirection can only be done before the actual request is sent. And if you redirect a main_frame
request, the user will see the data:
-URI instead of the requested URL.