I have a chrome extension and am currently using the webrequest api. My question is simple, is it possible to block and modify an AJAX request with the webrequest api? If not is there a work around to this?
PS. I am trying to inject pieces of HTML into a GMail email but the only solution I have found so far involves detecting all the various types of composes and then inject my HTML. This method is fine except its unstable, only about 70% of the time the insertion works.
If there is a better way, do let me know, thanks!
EDIT
Found a few alternate solutions if anyone needs it.
XMLHttpRequest.send
method to broadcast an event. You can modify the request before it gets sent out.There is currently no way to access or modify the response body using the webRequest api. There is an open issue in chromium requesting that feature. They have recently implemented the ability of accessing the request body, so there may be a chance they will also add this too.
You may have better luck with techniques that modify the XMLHttpRequest
object, as described in this answer. Here you have a step by step case study where the AJAX response is intercepted and modified.
Although you can detect XMLHttpRequests by explicitly setting the type property for chrome.webRequest to xmlhttprequest
, you will only be able to block asynchronous requests.
Synchronous XMLHttpRequests made from your extension are hidden from blocking event handlers in order to prevent deadlocks. Also the webRequest API will only expose calls that are made to URi patterns defined in the permissions area of your manifest.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With