You've to use a proxy like BrowserMob Proxy or MITMProxy.
I've started an extension for Codeception: https://github.com/edno/codeception-browsermob
I had a look at the mitmproxy as well. I wanted to build a docker image that contains a headless chrome, webdriver and the proxy.
I found a solutions that works for us (www.leankoala.com). As we are only using chrome it was possible to write a chrome extension that injects the needed code.