Chrome Extension - How to get HTTP Response Body?

后端 未结 3 909
栀梦
栀梦 2020-11-28 05:39

It seems to be difficult problem (or impossible??). I want to get and read HTTP Response, caused by HTTP Request in browser, under watching Chrome Extension background scrip

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 06:24

    This is definitely something that is not provided out of the box by the Chrome Extension ecosystem. But, I could find a couple of ways to get around this but both come with their own set of drawbacks.

    The first way is:

    1. Use a content script to inject our own custom script.
    2. Use the custom script to extend XHR's native methods to read the response.
    3. Add the response to the web page's DOM inside a hidden (not display: none) element.
    4. Use the content script to read the hidden response.

    The second way is to create a DevTools extension which is the only extension that provides an API to read each request.

    I have penned down both the methods in a detailed manner in a blog post here.

    Let me know if you face any issues! :)

提交回复
热议问题