From 7040dd91e5933f1c1cfea231d3da346f149a44df Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Mon, 19 Mar 2018 10:41:18 +0100 Subject: [PATCH] MOBILE-2379 iframe: Capture cross-origin errors when accessing contents --- www/core/directives/iframe.js | 24 +++++++++++++++++------- www/core/directives/recaptcha.js | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/www/core/directives/iframe.js b/www/core/directives/iframe.js index 52e444fd194..eb1eea14c0c 100644 --- a/www/core/directives/iframe.js +++ b/www/core/directives/iframe.js @@ -65,8 +65,7 @@ angular.module('mm.core') */ function redefineWindowOpen(element) { var el = element[0], - contentWindow = element.contentWindow || el.contentWindow, - contents = element.contents(); + contentWindow = element.contentWindow || el.contentWindow; if (!contentWindow && el && el.contentDocument) { // It's probably an . Try to get the window. @@ -131,11 +130,16 @@ angular.module('mm.core') } // Search sub frames. - angular.forEach(tags, function(tag) { - angular.forEach(contents.find(tag), function(subelement) { - treatFrame(angular.element(subelement)); + try { + var contents = element.contents(); + angular.forEach(tags, function(tag) { + angular.forEach(contents.find(tag), function(subelement) { + treatFrame(angular.element(subelement)); + }); }); - }); + } catch (ex) { + // Error getting iframe contents, probably due to a cross-origin problem. + } } /** @@ -146,7 +150,13 @@ angular.module('mm.core') * @return {Void} */ function treatLinks(element) { - var links = element.contents().find('a'); + var links; + try { + links = element.contents().find('a'); + } catch (ex) { + // Error getting iframe contents, probably due to a cross-origin problem. + } + angular.forEach(links, function(el) { var href = el.href; diff --git a/www/core/directives/recaptcha.js b/www/core/directives/recaptcha.js index 25bc0603b0a..8d0bdacf331 100644 --- a/www/core/directives/recaptcha.js +++ b/www/core/directives/recaptcha.js @@ -87,11 +87,11 @@ angular.module('mm.core') scope.closeModal(); }; contentWindow.recaptchaexpiredcallback = function() { + // Verification expired. Check the checkbox again. scope.expired = true; scope.model[scope.modelValueName] = ''; $timeout(); // Use $timeout to force a digest and update the view. }; - // Verification expired. Check the checkbox again. } }; } else if (scope.recaptchaV1Enabled && !scope.initializedV1) {