How to persist data in a Service Worker
<p>As of now, Chrome does not support passing additional data to push notifications received from GCM. So I have to execute a <code>fetch</code> from my Service Worker whenever I receive a push notification. So far, so good.</p>

<p><strong>But:</strong> I need to include a request parameter in my http request executed in <code>fetch</code>. How do I tell the service worker my parameter?</p>

<p><strong>What I've tried so far</strong></p>

<p>Using <code>postMessage</code> to tell my Service Worker the request parameter:</p>

<pre><code>var serviceWorkerData = {};

self.addEventListener('message', function (evt) 
{
    console.log('service worker received', evt.data);

    serviceWorkerData = evt.data.myData;
});

self.addEventListener('push', function(event)
{
    event.waitUntil
    (
        fetch("http://my.url", {
            method: 'post',
            body: 'myData=' + serviceWorkerData
        }).then(function(response)
        {
            //...
        })
    );
});
</code></pre>

<p><strong>Why this is not working</strong></p>

<p>But this is not persistent, i.e. after I close my browser and open it again, my <code>serviceWorkerData</code> is lost. <code>localStorage</code> is not available within service workers, so how do I get persistence here?</p>