From 9211b350dc9a3e4297a43c8c2b35e0e0356f8a01 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Mon, 3 Apr 2023 15:39:28 +0200 Subject: [PATCH] MOBILE-4303 iframe: Avoid trying to access inaccessible iframes With this change, the error about trying to access an iframe with different protocol, domain or port should no longer appear in console --- src/core/services/utils/iframe.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/core/services/utils/iframe.ts b/src/core/services/utils/iframe.ts index 7cd61dc00..3314fc8dc 100644 --- a/src/core/services/utils/iframe.ts +++ b/src/core/services/utils/iframe.ts @@ -231,6 +231,12 @@ export class CoreIframeUtilsProvider { * @returns Window and Document. */ getContentWindowAndDocument(element: CoreFrameElement): { window: Window | null; document: Document | null } { + const src = 'src' in element ? element.src : element.data; + if (!CoreUrlUtils.isLocalFileUrl(src)) { + // No permissions to access the iframe. + return { window: null, document: null }; + } + let contentWindow: Window | null = 'contentWindow' in element ? element.contentWindow : null; let contentDocument: Document | null = null;