How to use chrome.storage and runtime.connect in a Firefox WebExtensions add-on
<p>I'm trying to create a Firefox add-on that does the following:</p>

<ul>
<li>sends a message to a background script when the page body is clicked</li>
<li>the sent message is stored by the background script</li>
<li>the stored message is retrieved by the background script</li>
<li>when the add-in browser button is clicked that stored message is sent from the background script to the content script</li>
<li>the content script displays the received message</li>
</ul>

<p>I'm using Firefox version 48 for Windows and I can't get it to work.  Can someone point out what I'm doing wrong please.</p>

<p>Here is my content script:</p>

<pre><code>// setup message channel between this script and background script
var msgPort = chrome.runtime.connect({name:"msgPort"});

// fires when background script sends a message
msgPort.onMessage.addListener(function(msg) {
    console.log(msg.txt);
});

// sends a message to background script when page is clicked
document.body.addEventListener("click", function() {
    msgPort.postMessage({txt: "page clicked"});
});
</code></pre>

<p>Here is my background script:</p>

<pre><code>var msgPort;
var tmp;

// fires when message port connects to this background script
function connected(prt)
{
    msgPort = prt;
    msgPort.postMessage({txt: "message channel established"});
    msgPort.onMessage.addListener(gotMessage);
}

// fires when content script sends a message
frunction gotMessage(msg)
{
    // store the message
    chrome.storage.local.set({message : msg.txt});

    // read the stored message back again
    chrome.storage.local.get("message", function(item){
        tmp = item;
    });
}

// send the saved message to the content script when the add-on button is clicked
chrome.browserAction.onClicked.addListener(function() {
    msgPort.postMessage({txt: "saved message: "+tmp});
});

chrome.runtime.onConnect.addListener(connected);
</code></pre>

<p>And here is my manifest:</p>

<pre><code>{
    "name": "test",

    "manifest_version": 2,

    "version": "1.0",

    "permissions": ["activeTab","storage"],

    "content_scripts": [
        {
            "matches": ["&lt;all_urls&gt;"],
            "js": ["content.js"]
        }
    ],

    "background": {
        "scripts": ["background.js"]
    },

    "browser_action": {
        "default_title": "Go"
    },

    "applications": {
        "gecko": {
        "id": "test@example.com",
        "strict_min_version": "48.0a1"
        }
    }
}
</code></pre>