サーバーからhtmlコンテンツを取得し、ページ内にiframeを作成し、htmlを内部に挿入するchrome拡張機能を開発しています。したがって、「src」属性はありません。そのため、コンテンツ スクリプトは挿入されません。
manifest.js :
"background": { "scripts":["background.js"] },
"content_scripts":
[
{"js": ["toolbar.js"], "matches": ["http://*/*"]},
{"js": ["frame.js"], "matches": ["<all_urls>"], "all_frames":true}
],
"web_accessible_resources": [ "loader.gif","frame.js" ],
"permissions": [ "browsingData", "history", "storage", "tabs", "management", "<all_urls>" ]
background.js :
chrome.extension.onMessage.addListener(function(details)
{
if(details.message.sendBack)
{
chrome.tabs.sendMessage(details.sender.tab.id,details.message.data);
}
});
frame.js :
some function...
if...()
{
chrome.extension.sendMessage({ sendBack: true,data: data });
}
ツールバー.js :
function setContent(data)
{
iframe.contentDocument.open('text/html');
iframe.contentDocument.write(data);
iframe.contentDocument.close();
}
現在、iframe は、履歴の消去などのブラウザー関連の機能があるツールバーをホストしています。これらの関数には chrome.history と chrome.management への chrome-extension アクセスが必要なので、html オブジェクトと親拡張機能の間でメッセージを配信する必要があります。
問題は、src がローカル ファイルに設定されている場合でも、iframe に frame.js スクリプトが挿入されないことです。多分私は何か間違ったことをしているのかもしれませんが、スクリプトを挿入する方法が見つかりません。スクリプトを挿入することでそのようなメカニズムが可能になるかどうかさえわかりません。
スクリプトの相対 URL (chrome.tab.getURL) を取得しようとしましたが、スクリプトは実際に挿入されましたが、console.log(chrome) には拡張オブジェクトや使用できるメソッドが表示されませんでした (原因は手動注射)
どう思いますか?