Skip to content

Commit

Permalink
Merge pull request #10 from concord-consortium/fix-structured-clone
Browse files Browse the repository at this point in the history
Fix check for support of structured clone
  • Loading branch information
scytacki authored Oct 29, 2019
2 parents 50eba6d + 1765e64 commit 8680f1e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 32 deletions.
20 changes: 5 additions & 15 deletions dist/iframe-phone.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,32 +415,22 @@ module.exports = function ParentEndpoint(targetWindowOrIframeEl, targetOrigin, a
};

},{"./structured-clone":4}],4:[function(require,module,exports){
var featureSupported = false;
var featureSupported = {
'structuredClones': 0
};

(function () {
var result = 0;

if (!!window.postMessage) {
try {
// Safari 5.1 will sometimes throw an exception and sometimes won't, lolwut?
// When it doesn't we capture the message event and check the
// internal [[Class]] property of the message being passed through.
// Safari will pass through DOM nodes as Null iOS safari on the other hand
// passes it through as DOMWindow, gotcha.
window.onmessage = function (e) {
var type = Object.prototype.toString.call(e.data);
result = (type.indexOf("Null") != -1 || type.indexOf("DOMWindow") != -1) ? 1 : 0;
featureSupported = {
'structuredClones': result
};
};
// Spec states you can't transmit DOM nodes and it will throw an error
// postMessage implimentations that support cloned data will throw.
// postMessage implementations that support cloned data will throw.
window.postMessage(document.createElement("a"), "*");
} catch (e) {
// BBOS6 throws but doesn't pass through the correct exception
// so check error message
result = (e.DATA_CLONE_ERR || e.message == "Cannot post cyclic structures.") ? 1 : 0;
result = (e.DATA_CLONE_ERR || e.message === "Cannot post cyclic structures.") ? 1 : 0;
featureSupported = {
'structuredClones': result
};
Expand Down
20 changes: 5 additions & 15 deletions lib/structured-clone.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
var featureSupported = false;
var featureSupported = {
'structuredClones': 0
};

(function () {
var result = 0;

if (!!window.postMessage) {
try {
// Safari 5.1 will sometimes throw an exception and sometimes won't, lolwut?
// When it doesn't we capture the message event and check the
// internal [[Class]] property of the message being passed through.
// Safari will pass through DOM nodes as Null iOS safari on the other hand
// passes it through as DOMWindow, gotcha.
window.onmessage = function (e) {
var type = Object.prototype.toString.call(e.data);
result = (type.indexOf("Null") != -1 || type.indexOf("DOMWindow") != -1) ? 1 : 0;
featureSupported = {
'structuredClones': result
};
};
// Spec states you can't transmit DOM nodes and it will throw an error
// postMessage implimentations that support cloned data will throw.
// postMessage implementations that support cloned data will throw.
window.postMessage(document.createElement("a"), "*");
} catch (e) {
// BBOS6 throws but doesn't pass through the correct exception
// so check error message
result = (e.DATA_CLONE_ERR || e.message == "Cannot post cyclic structures.") ? 1 : 0;
result = (e.DATA_CLONE_ERR || e.message === "Cannot post cyclic structures.") ? 1 : 0;
featureSupported = {
'structuredClones': result
};
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"version": "1.2.0",
"description": "Convenient communication between the parent site and iframe based on window.postMessage()",
"main": "main.js",
"dependencies": {
},
"dependencies": {},
"devDependencies": {
"browserify": ">= 2.35 < 3.0"
},
Expand Down

0 comments on commit 8680f1e

Please sign in to comment.