From 344284b65e9d423901f929f5153a3959452fe060 Mon Sep 17 00:00:00 2001 From: Scot Gellock Date: Fri, 22 May 2015 13:54:12 -0700 Subject: [PATCH] check for a valid iframe.contentWindow inside the timeout call address a possible race condition where the call to the iframe's postMessage can happen after the frame has been closed. The initial check can succeed, but the call happens 'later' and it is possible for the frame to be closed. --- lib/utils/iframe.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/utils/iframe.js b/lib/utils/iframe.js index cdef8aa5..f73f7646 100644 --- a/lib/utils/iframe.js +++ b/lib/utils/iframe.js @@ -74,7 +74,9 @@ module.exports = { // on 'contentWindow'. if (iframe && iframe.contentWindow) { setTimeout(function() { - iframe.contentWindow.postMessage(msg, origin); + if (iframe && iframe.contentWindow) { + iframe.contentWindow.postMessage(msg, origin); + } }, 0); } } catch (x) {} @@ -140,7 +142,9 @@ module.exports = { // on 'contentWindow'. if (iframe && iframe.contentWindow) { setTimeout(function() { - iframe.contentWindow.postMessage(msg, origin); + if (iframe && iframe.contentWindow) { + iframe.contentWindow.postMessage(msg, origin); + } }, 0); } } catch (x) {}