XMLHttpRequest.prototype.open doesn't intercept ALL HTTP requests that are shown on the chrome-dev-tools

Viewed 228

I'm using a third-party embedded code that makes some HTTP request with request header origin different from mine.

When I try to intercept the HTTP requests with XMLHttpRequest, it doesn't intercept that request. I am assuming it is because it has a different origin. However, the chrome-dev-tools does intercept it.

let oldXHROpen = XMLHttpRequest.prototype.open;

XMLHttpRequest.prototype.open = function(method, url) {
  console.log(url)
  return oldXHROpen.apply(this, arguments);
}

It logs all the requests that have the request header origin as my domain. However, It doesn't log any requests that are shown in the dev-tools with a request header origin other than my domain.

1 Answers

If it has a different origin to your page, then that can only be because it is running on a different origin.

Probably it is inside an iframe (which is probably dynamically generated by the script you are using to embed the third-party code).

The Same Origin Policy prevents you intercepting the requests that are being sent between the user's browser and the third-party site for obvious security and privacy reasons.

Related