Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught DOMException: Failed to execute 'postMessage' on 'Window': An object could not be cloned

I'm trying to call

parent.postMessage(obj, 'whatever');

from within an iframe and I'm getting this error: Uncaught DOMException: Failed to execute 'postMessage' on 'Window': An object could not be cloned.

like image 532
nieve Avatar asked Feb 21 '17 19:02

nieve


1 Answers

It turns out the object I passed had methods, which is why the error message said An object could not be cloned.

In order to fix this, you can do the following:

obj = JSON.parse(JSON.stringify(obj));
parent.postMessage(obj, 'whatever');
like image 151
nieve Avatar answered Nov 03 '22 22:11

nieve