0

I checked the network tab on chrome dev tools, there are many request that being done, one of them is Facebook request that sending pixel data to Facebook. I want to track those request and get the data that is a GET request.

Is that possible to fetch those request url by JavaScript? Then how, I don't have any idea around it.

  <script>
    console.log('request tracking!');
    var origOpen = XMLHttpRequest.prototype.send;
    XMLHttpRequest.prototype.send = function() {
      console.log('request started!');
      this.addEventListener('load', function() {
        console.log('request completed!');
        console.log(this.responseURL);
      });
      origOpen.apply(this, arguments);
    };
  </script>

I tested this code, it returns some links but not all request that being done, at least get requests.

This is a sample get request I like to track https://www.facebook.com/tr/?id=245300970880426&ev=fb_page_view&dl=https%3A%2F%2Fgetmessiah.app%2Fdashboard&rl=&if=false&ts=1646638190415&sw=1600&sh=900&at=

Update It looks the Facebook request is gif, and till now I just fetched the list of xhr and fetch requsts.

enter image description here

Nasser Ali Karimi
  • 4,462
  • 6
  • 34
  • 77
  • Why are you trying to do this? It can definitely be done, but depending on your use case there's a very high chance there's an open source tool to do this for you – Nick Bailey Mar 07 '22 at 07:36
  • perhaps some code uses `fetch` instead of `XMLHttpRequest` – Bravo Mar 07 '22 at 07:44
  • 1
    @NickBailey context appears to be https://stackoverflow.com/q/71332934/1427878 – CBroe Mar 07 '22 at 07:59
  • @NickBailey Here is more details https://stackoverflow.com/questions/71332934/facebook-how-to-get-events-id-from-user-added-pixel-to-a-website. if it is possible may you give me some hint or start point so I can follow up? now I'm stuck without any idea. – Nasser Ali Karimi Mar 07 '22 at 09:16
  • @Bravo not fetch but yes they are in type gif and redirect. I'm checking the network and the request type is gif. – Nasser Ali Karimi Mar 07 '22 at 10:19
  • is this for a browser web extension, or your own web page? – Bravo Mar 07 '22 at 10:28
  • @Bravo I have an script that user can add it to the website, and all I want to do is with JavaScript on the web page. I tested the fetch it is also doesn't catch Facebook request. I think because it is type gif. but how I can track these gif requests? – Nasser Ali Karimi Mar 07 '22 at 12:00
  • simple ... you can't – Bravo Mar 07 '22 at 12:02
  • @Bravo why? can you share the reason behind it? or any other solution to do same thing? – Nasser Ali Karimi Mar 07 '22 at 12:08
  • 1
    OK, maybe you can, but it won't be easy ... the gifs are probably loaded by a script injecting an `` into the DOM ... the only way you'll track that is to look for [mutations on the DOM](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver/MutationObserver), and when an IMG tag is added "somewhere" you can then see what the `src` attribute is ... though, the iMG may be added to the DOM without `src` and `src` added later, so your mutation observer will need to not only watch for child list changes but also attribute changes – Bravo Mar 07 '22 at 12:13
  • it could also be an `` tag or `` tag though probably not likely – Bravo Mar 07 '22 at 12:14
  • Maybe using a Service Worker, https://stackoverflow.com/questions/43813770/how-to-intercept-all-http-requests-including-form-submits (not sure r/n whether those can access cross-origin requests as well though?) – CBroe Mar 07 '22 at 12:58
  • @CBroe thanks for info and guidance :), lets check them to find out if there is possibility – Nasser Ali Karimi Mar 07 '22 at 13:02

0 Answers0