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.

oma
  • 38,642
  • 11
  • 71
  • 99
Bogdan Gaza
  • 149
  • 2
  • 4
  • 1
    Why do you say that WebRequest doesn't help with that? Please expand on that. – Xan May 09 '14 at 10:03
  • 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. – Xan May 09 '14 at 10:21
  • So what is exactly meant by "intercept"? Please describe the normal workflow of the system, and how you want to modify that. – Xan May 09 '14 at 11:25

1 Answers1

-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/

webdevinci
  • 310
  • 3
  • 10
  • This will not work, at least not without a lot of modification. The extension lives in a separate context. – Xan Oct 11 '15 at 10:51
  • If it's a chrome extension, isn't window the same context? $(window).ajaxComplete(). It is working in my extension sanbox – webdevinci Oct 12 '15 at 11:14
  • Content scripts live in a [separate context](https://developer.chrome.com/extensions/content_scripts#execution-environment) 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. – Xan Oct 12 '15 at 11:24
  • See the duplicate target; Rob W explains it in detail. – Xan Oct 12 '15 at 11:24
  • 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 up – webdevinci Oct 12 '15 at 11:28
  • Then what will be solution for this. – Hardeep Singh Jan 04 '19 at 05:32