diff --git a/src/util.js b/src/util.js index dbc8de3f..3a1f5f7e 100644 --- a/src/util.js +++ b/src/util.js @@ -88,7 +88,7 @@ export default { } return; } - if (typeof MessagePort !== 'undefined' && MessagePort.prototype.isPrototypeOf(value)) { + if (Object.prototype.toString.call(value) === '[object MessagePort]') { throw new Error("Can't transfer the same stream twice."); } util.collectTransferables(value, collection); @@ -104,7 +104,7 @@ export default { restoreStreams: function(obj) { if (Object.prototype.isPrototypeOf(obj) && !Uint8Array.prototype.isPrototypeOf(obj)) { Object.entries(obj).forEach(([key, value]) => { // recursively search all children - if (MessagePort.prototype.isPrototypeOf(value)) { + if (Object.prototype.toString.call(value) === '[object MessagePort]') { obj[key] = new ReadableStream({ pull(controller) { return new Promise(resolve => {