1

If you get a page's initial HTML, can you detect subsequent ajax requests?

Much like you can in the Developer Console, but programmatically. Have searched extensively for a solution but found none.

SISYN
  • 2,209
  • 5
  • 24
  • 45

1 Answers1

1

You can use PerformanceObserver with entryType set to "resource"

function perf_observer(list, observer) { 
   // Process the "resource" event 
} 
var observer2 = new PerformanceObserver(perf_observer); 
observer2.observe({entryTypes: ["resource"]});

See

guest271314
  • 1
  • 15
  • 104
  • 177
  • Where exactly does the HTML go that we are "listening" to? – SISYN Jul 31 '17 at 14:27
  • @DanL Requirement is to observe all requests from `window`, yes? – guest271314 Jul 31 '17 at 23:58
  • Preferably to observe all requests from a string of HTML not currently loaded into the DOM. – SISYN Aug 01 '17 at 02:19
  • @DanL What do you mean by "from a string of HTML"? You can filter all of the requests, for example, by URL. If you know what URL that will be requested. Iterate the key, value pairs of each request, where the URL and initiator of the request is listed when `.getEntries()` is called. You can break the loop i a match is found, the observer will continue to observe all requests until disconnected, see https://stackoverflow.com/questions/43960770/get-actual-image-url-after-redirect/ – guest271314 Aug 01 '17 at 02:21