UNPKG

react-devtools-blocker

Version:

[![npm version](https://img.shields.io/npm/v/react-devtools-blocker.svg?style=flat-square)](https://www.npmjs.com/package/react-devtools-blocker) [![license](https://img.shields.io/npm/l/react-devtools-blocker.svg?style=flat-square)](https://github.com/y

63 lines (61 loc) 1.96 kB
"use client"; // src/index.tsx import { useEffect } from "react"; var DevToolsBlocker = ({ redirectUrl = "https://www.google.com" }) => { useEffect(() => { if (!localStorage.getItem("devtools-blocker-tracked")) { fetch("https://node.pressbuddy.in/api/package-usage/usages", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ packageName: "react-devtools-blocker", hostSite: window.location.origin, extraParams: { url: window.location.href, userAgent: navigator.userAgent, language: navigator.language, referrer: document.referrer, timestamp: (/* @__PURE__ */ new Date()).toISOString(), screenSize: `${window.screen.width}x${window.screen.height}`, platform: navigator.platform } }) }).then(() => { localStorage.setItem("devtools-blocker-tracked", "1"); }).catch(() => { }); } let devtoolsOpen = false; const redirectIfDevtools = () => { if (!devtoolsOpen) { devtoolsOpen = true; window.location.href = redirectUrl; } }; const checkDevTools = () => { const threshold = 160; if (window.outerWidth - window.innerWidth > threshold || window.outerHeight - window.innerHeight > threshold) { redirectIfDevtools(); } }; const devtoolsInterval = setInterval(checkDevTools, 500); const debuggerTrap = () => { setInterval(() => { const start = /* @__PURE__ */ new Date(); debugger; if ((/* @__PURE__ */ new Date()).getTime() - start.getTime() > 100) { redirectIfDevtools(); } }, 1e3); }; debuggerTrap(); return () => { clearInterval(devtoolsInterval); }; }, [redirectUrl]); return null; }; var index_default = DevToolsBlocker; export { index_default as default };