Intercept AJAX responses in Chrome Extension [duplicate]
Asked Answered
T

1

14

We're building a chrome extension on top of an existing system, to help with a few tasks.

It's AJAX intense and it would be far more efficient than scraping html and triggering events to intercept some of the AJAX responses.

Example: Frome chrome console, networks tab, you see the beautiful JSON: enter image description here

How can a Chrome Extension get to that JSON ?

I've tried WebRequest but it appear it does't allow to do this.

Tenacious answered 9/5, 2014 at 10:2 Comment(3)
Why do you say that WebRequest doesn't help with that? Please expand on that.Hesky
Also, your question as of now is under risk of being closed as "opinion-based". Instead of broadly asking for a "de facto way", please include more specific details about your task.Hesky
So what is exactly meant by "intercept"? Please describe the normal workflow of the system, and how you want to modify that.Hesky
P
-2

If you don't mind using jQuery, you can use the

$.ajaxComplete( function( Event event, jqXHR jqXHR, PlainObject ajaxOptions ))

method on the document.

In the callback you can grab all of the information about any of the events and log them accordingly.

http://api.jquery.com/ajaxcomplete/

Peeved answered 11/10, 2015 at 10:24 Comment(6)
This will not work, at least not without a lot of modification. The extension lives in a separate context.Hesky
If it's a chrome extension, isn't window the same context? $(window).ajaxComplete(). It is working in my extension sanboxPeeved
Content scripts live in a separate context from the page, and executing this without additional techniques will lead to intercepting only AJAX calls 1) made from extension context, 2) made with jQuery.Hesky
See the duplicate target; Rob W explains it in detail.Hesky
Got ya, I don't have much experience with extensions, just used this when we needed to intercept 3rd party ajax calls on our site. Thanks for clearing upPeeved
Then what will be solution for this.Disesteem

© 2022 - 2024 — McMap. All rights reserved.