From 56ecdec2cbc038c324db436fd69bc901992b247f Mon Sep 17 00:00:00 2001 From: infinite-persistence <64950861+infinite-persistence@users.noreply.github.com> Date: Fri, 26 Nov 2021 06:24:51 -0800 Subject: [PATCH] Restore "don't run SP script on iframe (368)" + lint/format (#373) --- ui/component/app/view.jsx | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/ui/component/app/view.jsx b/ui/component/app/view.jsx index e232f15c4..158fecb80 100644 --- a/ui/component/app/view.jsx +++ b/ui/component/app/view.jsx @@ -332,6 +332,18 @@ function App(props: Props) { // add secure privacy script useEffect(() => { + function inIframe() { + try { + return window.self !== window.top; + } catch (e) { + return true; + } + } + + if (inIframe()) { + return; + } + const script = document.createElement('script'); script.src = securePrivacyScriptUrl; script.async = true; @@ -359,7 +371,7 @@ function App(props: Props) { // haven't done a gdpr check, do it now if (gdprRequired === null) { - (async function() { + (async function () { const response = await fetch(getLocaleEndpoint); const json = await response.json(); const gdprRequiredBasedOnLocation = json.data.gdpr_required; @@ -370,8 +382,8 @@ function App(props: Props) { document.head.appendChild(script); // $FlowFixMe document.head.appendChild(cmpScript); - // note we don't need gdpr, save to session - } else if (gdprRequiredBasedOnLocation === false) { + // note we don't need gdpr, save to session + } else if (gdprRequiredBasedOnLocation === false) { localStorage.setItem('gdprRequired', 'false'); } })();