diff --git a/src/App.jsx b/src/App.jsx index 042f26c..f746608 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -26,6 +26,7 @@ import useSubscriptionManager from './useSubscriptionManager.js'; import useSessionManager from './useSessionManager.js'; import ExtendSubscriptionModal from './Pages/ExtentedModal/ExtendSubscriptionModal.jsx'; import devtools from 'devtools-detect'; +import { useDevToolsDetection } from './utils/useDevToolsDetection.js'; const isCapacitor = () => !!window.Capacitor?.isNativePlatform?.(); @@ -78,7 +79,7 @@ const AppRoutes = () => { sessionStorage.setItem('navStack', JSON.stringify(stack)); console.log('📍 Stack:', stack); } - } catch (e) {} + } catch (e) { } }, [location.pathname, location.search]); // ✅ Web — block browser back button @@ -171,45 +172,66 @@ const AppRoutes = () => { }; }, [navigate, location.pathname, location.search]); // mohan - useEffect(() => { - if (isMobile || isIOS) { - console.log('📱 Mobile/iOS device → skipping DevTools detection'); - return; - } - const checkDevTools = setInterval(() => { - if (devtools.isOpen && !devToolsOpen) { - setDevToolsOpen(true); - document.body.innerHTML = - "

Close Inspect to continue using the application.

"; - } else if (!devtools.isOpen && devToolsOpen) { - setDevToolsOpen(false); + // useEffect(() => { + // if (isMobile || isIOS) { + // console.log('📱 Mobile/iOS device → skipping DevTools detection'); + // return; + // } + // const checkDevTools = setInterval(() => { + // if (devtools.isOpen && !devToolsOpen) { + // setDevToolsOpen(true); + // document.body.innerHTML = + // "

Close Inspect to continue using the application.

"; + // } else if (!devtools.isOpen && devToolsOpen) { + // setDevToolsOpen(false); - setTimeout(() => { - window.location.reload(); - }, 100); + // setTimeout(() => { + // window.location.reload(); + // }, 100); - clearInterval(checkDevTools); - } + // clearInterval(checkDevTools); + // } - if (!devtools.isOpen) { - let before = performance.now(); + // if (!devtools.isOpen) { + // let before = performance.now(); - let after = performance.now(); + // let after = performance.now(); - let executionDelay = after - before; + // let executionDelay = after - before; - if (executionDelay > 100) { - setDevToolsOpen(true); - document.body.innerHTML = - "

Close Inspect to continue using the application.

"; - } else { - setDevToolsOpen(false); - } - } - }, 1000); + // if (executionDelay > 100) { + // setDevToolsOpen(true); + // document.body.innerHTML = + // "

Close Inspect to continue using the application.

"; + // } else { + // setDevToolsOpen(false); + // } + // } + // }, 1000); - return () => clearInterval(checkDevTools); - }, [devToolsOpen]); + // return () => clearInterval(checkDevTools); + // }, [devToolsOpen]); + const isBlocked = useDevToolsDetection(() => { + // optional: log, notify, etc. + console.warn('DevTools detected'); + }); + + if (isBlocked) { + return ( +
+

+ DevTools detected. Please close it to continue. +

+
+ ); + } if (extendModel) { return ( threshold || + window.outerHeight - window.innerHeight > threshold + ); + }, + + checkConsole() { + let detected = false; + const element = new Image(); + Object.defineProperty(element, 'id', { + get: () => { detected = true; } + }); + console.log('%c', element); + console.clear(); + return detected; + }, + + checkDebugger() { + if (import.meta.env.DEV) return false; + const start = performance.now(); + // eslint-disable-next-line no-debugger + debugger; + const end = performance.now(); + return end - start > 100; + }, + + checkToString() { + let detected = false; + const div = document.createElement('div'); + Object.defineProperty(div, 'id', { + get: function () { + detected = true; + return 'id'; + } + }); + console.log(div); + console.clear(); + return detected; + }, + + detect() { + return ( + this.checkWindowSize() || + this.checkConsole() || + this.checkDebugger() || + this.checkToString() + ); + } +}; + +export default DevToolsDetector; + + + +import { useEffect, useState } from 'react'; + +const isMobileOrIOS = () => + /iPhone|iPad|iPod|Android/i.test(navigator.userAgent); + +export const useDevToolsDetection = (onDetected) => { + const [isBlocked, setIsBlocked] = useState(false); + + useEffect(() => { + if (isMobileOrIOS()) return; + + const interval = setInterval(() => { + const detected = DevToolsDetector.detect(); + + if (detected && !isBlocked) { + setIsBlocked(true); + onDetected?.(); + } else if (!detected && isBlocked) { + setIsBlocked(false); + clearInterval(interval); + setTimeout(() => window.location.reload(), 100); + } + }, 1000); + + return () => clearInterval(interval); + }, [isBlocked]); + + return isBlocked; +}; \ No newline at end of file