I'd like to have my chrome extension communicate with a native application for the response body when making requests to certain urls. For example, when chrome makes a request to https://www.example.com, the request is intercepted (as in chrome.webRequest.onBeforeRequest). Let's say that when communicating with the native app, the native app resolves that the html for the site should be <div>Example HTML</div>— it would send to the chrome extension that new response body, which will be used as an alternative to actually making the request to example.com.
It seems initially obvious that the extension could simply redirect to a new page hosted locally whose html/css/js is being managed by the native app. But this breaks if the page's code tells chrome to load another page (e.g. <script src="foo.js">), unless the native app wants to interpret that itself.
So what I'm looking for is something similar to chrome.webRequest.onBeforeRequest.addListener(function(details) {return}, filter, ["blocking"]), but it returns the data that chrome should use instead of continuing the request and getting a response body.
Note: the chrome.proxy API is not correct as it communicates with a server, not a native app.