From 69024aa9e20147f1a75831fd7369a36b86074ecd Mon Sep 17 00:00:00 2001 From: Pavel Ivanov Date: Mon, 9 Dec 2024 10:54:14 +0200 Subject: [PATCH] fix: skip React detection in iframes and popups --- packages/extension/src/content/index.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/extension/src/content/index.ts b/packages/extension/src/content/index.ts index 8c2b7134..e866291e 100644 --- a/packages/extension/src/content/index.ts +++ b/packages/extension/src/content/index.ts @@ -2,6 +2,9 @@ import styles from '../assets/css/styles.css?inline'; import { BroadcastSchema } from '../types/messages'; import { loadCss, broadcast } from '../utils/helpers'; +const isIframe = window !== window.top; +const isPopup = window.opener !== null; + chrome.runtime.onMessage.addListener((message: unknown, _sender, sendResponse) => { const result = BroadcastSchema.safeParse(message); @@ -43,7 +46,12 @@ const getCSPRulesState = async () => chrome.runtime.sendMessage({ domain: window.location.origin, }, }).then((cspRulesEnabled) => { + if (isIframe || isPopup) { + return false; + } + broadcast.postMessage('react-scan:is-csp-rules-enabled', cspRulesEnabled); + return cspRulesEnabled.enabled; }); @@ -71,14 +79,6 @@ const init = (() => { const isCSPRulesEnabled = await getCSPRulesState(); const toolbarContent = document.getElementById('react-scan-toolbar-content'); - // window.dispatchEvent( - // new CustomEvent('react-scan:state-change', { - // detail: { enabled: isCSPRulesEnabled } - // }) - // ); - - // broadcast.postMessage('react-scan:state-change', { enabled: isCSPRulesEnabled }); - if (isCSPRulesEnabled) { // send message to the extension to disable the rules await chrome.runtime.sendMessage({