I am trying to post a message to a service worker instance. I get the following error:
Failed to execute 'postMessage' on 'ServiceWorker': function (){ obj.removeListener(ev, fn); } could not be cloned.
My code is as follows:
var socket = io();
function onYouTubeIframeAPIReady() {
//Tell the service worker who I am
navigator.serviceWorker.ready.then(serviceWorkerRegistration => {
navigator.serviceWorker.controller.postMessage({
name: 'socketInit',
value: socket
});
});
}
Any idea why this happens?
Actually found the answer right away, it's in the docs. You basically can't have a
Function
-type property (which probably is there somewhere inside the io() object) because it can't be cloned:A
structured-clonable-type
being defined as: