I've noticed a strange behaviour on Firefox that iframe pages loaded via ServiceWorker lost parent's referrer.
I have a page embedded via iframe into parent site. The page uses parent.postMessage() to communicate with the parent window and takes document.referrer as a targetOrigin parameter. It also registers a ServiceWorker to use a cached version of a content. When the iframe page is loaded for the first time and ServiceWorker is not registered yet the document.referrer has a value of the URL of parent's page as expected. But when I refresh the site and iframe loads a cached version of the page returned by ServiceWorker the document.referrer is empty. Are there additional steps that must be done in order to maintain parent's referrer in this cases (like policy headers)? Curiously this does not happen on a webkit-based browers.
ServiceWorker code:
const cacheName = 'XXX';
const resources = [...];
self.addEventListener('install', event => {
event.waitUntil(
caches.open(cacheName)
.then(cache => cache.addAll(resources))
);
});
self.addEventListener('fetch', function (event) {
event.respondWith(
caches.match(event.request)
.then(function (response) {
if (response) {
return response;
}
return fetch(event.request);
})
);
});
Thanx,