Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix check for support of structured clone #10

Merged
merged 3 commits into from
Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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