0

I can't find any information on how to recover the response of a specific request from the network tab of the browser.

I have an issue when trying to poll remote API URL from browser as the remote domain does not have CORS configured correctly and I lack access to configure it so I must both launch the request and recover the response.

I have tried placing the request in an iframe and an async image download with the URL of the API. Both cases with the same issue. The request are executed but question is how to recover the response. I have looked at devtool.network both for chrome and mozilla but can find examples with the response being returned or a lot of information on the requests. I think my question can be related to API Reference for chrome.devtools.network That one never got solved. If somebody can share information on devtools with me or a workarround to my use case (avoid CORS) both would work as a solutions for me.

I only need to be pointed out in the way of documentation I can use or practical example of a web request response being recovered.

Ivo Yordanov
  • 146
  • 1
  • 8
  • Why do you need an API for devtools for this? Just go into the Network tab, click on the URL of the request, then you can click on Response to see the response. – Barmar Sep 04 '19 at 22:51
  • If I could do that I wouldn't be asking this question. – Ivo Yordanov Sep 04 '19 at 23:27
  • Oh, now I see, you're trying to figure out how to trick the browser into letting you make a cross-origin AJAX request, by putting the API URL into something else and then accessing the raw response in your code. If you could do this, it would be a security hole in the browser, and they'd eventually fix it to block you. So I suggest you seek an alternative method. The usual solution is to run a proxy on your server. – Barmar Sep 04 '19 at 23:30
  • Strictly technically speaking the browser is tricked into doing the cross-origin request. Issue is with recovering the response as there isn't much information on the devtools.network API. I have though of the proxy but problem is that CORS is not configured at all at the server I am not sure it will work. If the origin was set to none it would but with it not configured at all... The API method on the server is just for backend polling. – Ivo Yordanov Sep 05 '19 at 00:24
  • You don't need CORS if the request is coming from the server, only browsers check CORS. – Barmar Sep 05 '19 at 00:25
  • Issue is I need to do it from the browser..In standard server to server everything works fine. – Ivo Yordanov Sep 05 '19 at 00:27
  • That's why you use a proxy on your server. The request goes browser->yourServer->APIServer, and the proxy forwards the response back. – Barmar Sep 05 '19 at 00:29
  • Your server is in the same domain as the web page, so there's no CORS problem there. – Barmar Sep 05 '19 at 00:30
  • Problem is my proxy is not on the same domain as the webpage. Although maybe I could enable Origin: * for the proxy. – Ivo Yordanov Sep 05 '19 at 00:32
  • 1
    Yes, `Access-Control-Allow-Origin: *` would work, that's what we do. – Barmar Sep 05 '19 at 00:33
  • Ok.. Will try to use the proxy and see if it works for this. I still would love to know if there is doc on the devtools.network API though... Seems like something that can come in handy. – Ivo Yordanov Sep 05 '19 at 00:35
  • The other question has a link to documentation: https://developer.chrome.com/extensions/devtools_network#method-getHAR – Barmar Sep 05 '19 at 00:37
  • But depending on this in a production application seems wrong. It ties you to a specific browser. I also think this can only be used from extensions, not web applications. – Barmar Sep 05 '19 at 00:38
  • That is the standard documentation and is very limited. There must be more info on the API somewhere out there. – Ivo Yordanov Sep 05 '19 at 00:38
  • The main page https://developer.chrome.com/extensions/devtools is titled "Extending DevTools". It's only for adding DevTools extensions, I don't think it can be used in applications. – Barmar Sep 05 '19 at 00:39
  • The devtools.network API is supposed to be the same with minor changes for chrome and mozila. – Ivo Yordanov Sep 05 '19 at 00:39
  • Ok so it doesn't serve me. Hard thing to trick the browser. This front end stuff is nightmare.. I should stick with back end.. Thx for the proxy! Post it as an answer so I can choose it as soon as I can test. – Ivo Yordanov Sep 05 '19 at 00:46

0 Answers0