2016-09-23 3 views
0

私は特定のサーバーへの最初の要求を傍受する必要があります。http://google.comとし、現在のタブのルート内にレンダリングするのではなく、最初にiframeの2つのページを作成します。http://google.com 2番目のものはレンダリングされますhttp://bing.comと言うことができます。Chrome拡張機能でhtmlページを読み込む前に作成できますか?

私はこのようなものが必要になります。実際に私は非常に最初の要求を傍受する方法を知っている

<!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> 

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

が、次は何を行うには?

答えて

2

Chrome拡張子can't directly modify http response bodyたとえば、このリクエストを定義済みのHTMLテンプレートにリダイレクトするなど、いくつかの回避策を使用できます。

chrome.webRequest.onBeforeRequest.addListener(
    function(details) 
    { 
     return { redirectUrl: chrome.runtime.getURL('template.html')}; 
    }, 
    {urls: ["*://www.baidu.com/*"]}, 
    ['blocking'] 
); 
+0

このページは他の場所でホストするか、内線で同梱できますか? – Anatoly

+1

@Anatolyは、あなたのニーズによって異なりますが、私の例ではテンプレートが拡張機能にバンドルされていると仮定しています。 –

関連する問題