0

I need to intercept the very first request to specific server, let it be http://google.com and instead of render it inside root of the current tab create a page with two iframes, in the first iframe will be rendered site originally requested, http://google.com, in second one will be rendered lets say http://bing.com.

I need something like this:

<!DOCTYPE html>
<html>
<body>

<iframe src="http://www.google.com">
  <p>Your browser does not support iframes.</p>
</iframe>
<iframe src="http://www.bing.com">
  <p>Your browser does not support iframes.</p>
</iframe>

</body>
</html>

Actually I know how to intercept the very first request:

chrome.webRequest.onBeforeRequest.addListener(
    function(details)
    {
        console.log(details.requestBody);
    },
    {urls: ["*://google/*"]},
    ['requestBody']
);

but what to do next?

Anatoly
  • 5,056
  • 9
  • 62
  • 136

1 Answers1

2

Chrome extension can't directly modify http response body, you may want to use some workarounds, for example, redirect this request to a predefined html template.

chrome.webRequest.onBeforeRequest.addListener(
    function(details)
    {
        return { redirectUrl: chrome.runtime.getURL('template.html')};
    },
    {urls: ["*://www.baidu.com/*"]},
    ['blocking']
);
Community
  • 1
  • 1
Haibara Ai
  • 10,703
  • 2
  • 31
  • 47