Skip to content

Commit

Permalink
fix: skip React detection in iframes and popups
Browse files Browse the repository at this point in the history
  • Loading branch information
pivanov committed Dec 9, 2024
1 parent 22ddf2d commit 69024aa
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions packages/extension/src/content/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
});

Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 69024aa

Please sign in to comment.