"DataCloneError: object cannot be cloned." in firefox 34

Using the specified function to send a message, but receiving the error "DataCloneError: object cannot be cloned." at Line "target ['postMessage'] (message, target_url.replace (/ ([^:] +: // [^ /] +). * /, '$ 1'));" in FireFox-34, the same code works fine in Chrome and an older version of FireFox.

var storage = function() {
    return {
           postMessage : function(message, target_url, target) {
           if (!target_url) { 
              return; 
           }
           var target = target || parent;  // default to parent
           if (target['postMessage']) { 
                   // the browser supports window.postMessage, so call it with a targetOrigin
                   // set appropriately, based on the target_url parameter.
                   target['postMessage'](message, target_url.replace( /([^:]+:\/\/[^\/]+).*/, '$1'));
               }               
         }
    }
}();
+4
source share
1 answer

postMessagesends messages using the structured cloning algorithm in Firefox, and because of this there are some things that you need to configure before sending.

, , - . URL- postMessage :

someWindow.postMessage(window.location, '*');
// ERROR

, :

var windowLocation = '' + window.location;
someWindow.postMessage(windowLocation, '*');
// WORKS

, , , .

+6

Source: https://habr.com/ru/post/1568248/


All Articles