Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>UPDATE</strong><br> As of Chrome 20 you can now use the Storage api.....<br> <a href="http://code.google.com/chrome/extensions/storage.html" rel="nofollow">http://code.google.com/chrome/extensions/storage.html</a></p> <p><strong>Old way</strong><br> What I do is create an iframe that points to a page in my extension that has a script that gets the settings I need from local storage and then sends that to its parent in a message which the content script then gets.....well that was a crap explanation, the code says it better ;)....... </p> <p><strong>Content Script</strong></p> <pre><code>// 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); } </code></pre> <p><strong>gimmeSettings.html's JS</strong> </p> <pre><code>// post the message with our settings parent.postMessage( localStorage.getItem("testing"), "*" ); </code></pre> <p><strong>Options.html's JS</strong></p> <pre><code>localStorage.setItem("testing","bleh"); </code></pre> <p><strong>Manifest</strong></p> <pre><code>{ "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": ["&lt;all_urls&gt;"], "js" : ["myscript.js"], "run_at":"document_idle" } ], "permissions": [ "tabs", "&lt;all_urls&gt;" ], "manifest_version": 2, "web_accessible_resources": [ "gimmeSettings.html" ], "options_page": "options.html", "version":"1.0" } </code></pre> <p>Some things to note....<br> Other pages and extensions can easily use this to also get the settings from your extension, so dont use any sensitive data with this method.<br> From the best I can tell there is no way for them to alter your settings through that page tho, if anyone knows different please explain.<br> Im using manifest version 2 and have set the page gimmeSettings to be accessible. If you dont know the differences manifest version 2 add you really should read up on it.... <a href="http://code.google.com/chrome/extensions/trunk/manifestVersion.html" rel="nofollow">http://code.google.com/chrome/extensions/trunk/manifestVersion.html</a> </p> <p>And if you want a working example then go here.....<br> <a href="http://forum.valorsolo.com/viewtopic.php?f=36&amp;t=375" rel="nofollow">http://forum.valorsolo.com/viewtopic.php?f=36&amp;t=375</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload