更新
Chrome 20以降、Storage APIを使用できるようになりました.....
http://code.google.com/chrome/extensions/storage.html
古い方法
私がしていることは、ローカルストレージから必要な設定を取得するスクリプトを持つ拡張機能のページを指すiframeを作成し、それをコンテンツスクリプトが取得するメッセージで親に送信することです.... .まあ、それはがらくたの説明でした、コードはそれをよりよく言います;).......
コンテンツ スクリプト
// create the iframe for our page that sends the settings
var el = document.createElement("iframe");
el.setAttribute('src', chrome.extension.getURL("gimmeSettings.html"));
el.style.visibility="hidden";
document.body.appendChild(el);
// create the listner that listens for a message from our page that sends the settings
window.addEventListener("message", receiveSettings, false);
// function that gets called when we recieve a message from the page that sends the settings
function receiveSettings(event) {
//check to make sure the message came from our page
if (event.origin !== "chrome-extension://"+chrome.i18n.getMessage("@@extension_id")) return;
//message came from our extension, do stuff with it
console.debug(event.data);
// clean up
window.removeEventListener("message", receiveSettings, false);
el.parentNode.removeChild(el);
}
gimmeSettings.html の JS
// post the message with our settings
parent.postMessage( localStorage.getItem("testing"), "*" );
Options.html の JS
localStorage.setItem("testing","bleh");
マニフェスト
{
"name": "Getting at an extensions local storage from a content script",
"description" : "Getting at an extensions local storage from a content script. Be aware that other pages/extensions can use this to get at your settings, but not change them...so dont include sensitvie data.",
"content_scripts": [
{
"matches": ["<all_urls>"],
"js" : ["myscript.js"],
"run_at":"document_idle"
}
],
"permissions": [
"tabs", "<all_urls>"
],
"manifest_version": 2,
"web_accessible_resources": [
"gimmeSettings.html"
],
"options_page": "options.html",
"version":"1.0"
}
注意すべき点....
他のページや拡張機能は、これを使用して拡張機能から設定を簡単に取得できるため、この方法で機密データを使用しないでください。
私が知る限り、彼らがそのページからあなたの設定を変更する方法はありません.誰かが違うことを知っているなら、説明してください.
私はマニフェスト バージョン 2 を使用しており、ページ gimmeSettings にアクセスできるように設定しています。マニフェスト バージョン 2 の違いがわからない場合は、実際に読んで ください。 http://code.google.com/chrome/extensions/trunk/manifestVersion.html
実際の例が必要な場合は、ここにアクセスしてください.....
http://forum.valorsolo.com/viewtopic.php?f=36&t=375