Intercepting Network Requests and Modifying Response Body (with delay) in Chrome Extension MV3

1,042 views
Skip to first unread message

Tamar Y

unread,
Apr 8, 2024, 8:18:56 AM4/8/24
to Chromium Extensions
In Chrome extension MV3, I want to intercept network requests and modify the response body

My goal is to find a way to track a specific network call, delay it, and modify the response if necessary.
Let's take the example of a user trying to reach https://facebook.com
make a request to google.com and replace only the html content returned from FB with Google HTML.
By manipulating the response only (without changing the url)
We also have to wait for Google to respond to our request, which may take some time.

I checked:

Injecting a script into the DOM to override XHR: This method proves ineffective as the script is injected after the initial request to the target URL has already been made. Moreover, I seek to modify the response at the network level rather than altering the response/responseText directly.

Declarative Net Request (DNR) or similar MV3 approaches: These options do not offer the capability to modify or delay requests, rendering them unsuitable for my requirements.

Do we have another options/ any workarounds within MV3 extensions? Any insights or suggestions would be appreciated.

wOxxOm

unread,
Apr 8, 2024, 3:40:21 PM4/8/24
to Chromium Extensions, Tamar Y
You can do it in Firefox, but there's no way in Chrome and its developers never expressed any interest in providing such capability. The workaround is to write a (local) proxy server.
Reply all
Reply to author
Forward
0 new messages