Skip to content

Commit 3099553

Browse files
committed
detectInspectElement
1 parent 487cc65 commit 3099553

File tree

1 file changed

+103
-38
lines changed

1 file changed

+103
-38
lines changed

dist/secure-web.js

+103-38
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,11 @@ function noScreenshot(options, overlayId) {
117117
document.addEventListener('contextmenu', event => event.preventDefault());
118118

119119
// clear console every secound
120-
clearConsoleArea();
121-
120+
if(clearConsole) {
121+
clearConsoleArea();
122+
}
122123
// detect if inspect element open
123-
detectInspectElement(clearSensitiveContent);
124+
detectInspectElement(clearSensitiveContent , overlayId);
124125
}
125126

126127
if (disablePrintScreen) {
@@ -205,7 +206,7 @@ function noScreenshot(options, overlayId) {
205206

206207
function escListener(event) {
207208
if (event.key === 'Escape') {
208-
HideOverlayScreen(overlayId);
209+
HideOverlayScreen(overlayId , clearSensitiveContent);
209210
// document.body.removeChild(overlay);
210211
// document.body.style.pointerEvents = 'auto'; // Re-enable pointer events on body
211212
//document.removeEventListener('keydown', escListener);
@@ -278,7 +279,7 @@ function overlayScreen(overlayId) {
278279
}
279280

280281

281-
function HideOverlayScreen(overlayId) {
282+
function HideOverlayScreen(overlayId , clearSensitiveContent = false) {
282283
if (overlayId) {
283284
const customOverlay = document.getElementById(overlayId);
284285
if (customOverlay) {
@@ -290,13 +291,13 @@ function HideOverlayScreen(overlayId) {
290291
return;
291292
}
292293
}
294+
if(clearSensitiveContent) {
295+
location.reload();
296+
}
293297
var overlay = document.getElementById('no-screenshot-overlay');
294298
document.body.removeChild(overlay);
295299
document.body.style.pointerEvents = 'auto'; // Re-enable pointer events on body
296300
//document.removeEventListener('keydown', escListener);
297-
if(clearSensitiveContent) {
298-
location.reload();
299-
}
300301
}
301302

302303

@@ -327,43 +328,108 @@ function clearSensitiveData(selector) {
327328
if (element) {
328329
element.innerHTML = '';
329330
}
331+
}else{
332+
const element = document.querySelector('body');
333+
element.innerHTML = '';
330334
}
331335
}
332336
}
333337

334338

335-
function detectInspectElement(clearSensitiveContent){
336-
(function () {
337-
let devtoolsOpen = false;
338-
const detectDevTools = () => {
339-
const threshold = 160;
340-
const isDevToolsOpen = () => {
341-
// Detect if the developer tools are open by checking dimensions
342-
const widthDiff = window.outerWidth - window.innerWidth;
343-
const heightDiff = window.outerHeight - window.innerHeight;
344-
return widthDiff > threshold || heightDiff > threshold;
345-
};
346-
347-
if (isDevToolsOpen()) {
348-
if (!devtoolsOpen) {
349-
devtoolsOpen = true;
350-
alert('Developer tools are open!');
351-
console.warn('Developer tools are open!');
352-
overlayScreen(overlayId);
353-
clearSensitiveData(clearSensitiveContent);
354-
}
355-
} else {
356-
if (devtoolsOpen) {
357-
devtoolsOpen = false;
358-
HideOverlayScreen(overlayId);
359-
}
339+
// function detectInspectElement(clearSensitiveContent , overlayId){
340+
// let threshold = 160;
341+
// // let threshold = Math.max(window.outerWidth - window.innerWidth, window.outerHeight - window.innerHeight) + 10;
342+
//
343+
// // Initial adjustment of the threshold
344+
// window.addEventListener('resize', () => {
345+
// threshold = Math.max(window.outerWidth - window.innerWidth, window.outerHeight - window.innerHeight) - 10;
346+
// console.log('Resize threshold', threshold);
347+
// });
348+
//
349+
// // trigger resize event
350+
// (function () {
351+
// // threshold = Math.max(window.outerWidth - window.innerWidth, window.outerHeight - window.innerHeight) + 10;
352+
// let devtoolsOpen = false;
353+
// const detectDevTools = () => {
354+
// console.log('threshold', threshold);
355+
// const isDevToolsOpen = () => {
356+
// // Detect if the developer tools are open by checking dimensions
357+
// const widthDiff = Math.abs( window.outerWidth - window.innerWidth);
358+
// const heightDiff = Math.abs( window.outerHeight - window.innerHeight);
359+
// console.log('widthDiff', widthDiff);
360+
// console.log('heightDiff', heightDiff);
361+
// return widthDiff > threshold || heightDiff > threshold;
362+
// };
363+
//
364+
// if (isDevToolsOpen()) {
365+
// if (!devtoolsOpen) {
366+
// devtoolsOpen = true;
367+
// alert('Developer tools are open!');
368+
// console.warn('Developer tools are open!');
369+
// clearSensitiveData(clearSensitiveContent);
370+
// overlayScreen(overlayId);
371+
// }
372+
// } else {
373+
// if (devtoolsOpen) {
374+
// devtoolsOpen = false;
375+
// HideOverlayScreen(overlayId , clearSensitiveContent);
376+
// }
377+
// }
378+
// };
379+
//
380+
// // Run the check every second
381+
// setInterval(detectDevTools, 1000);
382+
// })();
383+
// }
384+
385+
386+
function detectInspectElement(clearSensitiveContent, overlayId) {
387+
let threshold = Math.max(window.outerWidth - window.innerWidth, window.outerHeight - window.innerHeight) + 10;
388+
let devtoolsOpen = false;
389+
390+
// Function to check if DevTools is open
391+
const isDevToolsOpen = () => {
392+
const widthDiff = Math.abs(window.outerWidth - window.innerWidth);
393+
const heightDiff = Math.abs(window.outerHeight - window.innerHeight);
394+
console.log('widthDiff', widthDiff);
395+
console.log('heightDiff', heightDiff);
396+
397+
// Check for width or height differences above threshold
398+
return widthDiff > threshold || heightDiff > threshold;
399+
};
400+
401+
// Function to check for debugger
402+
const detectDebugger = () => {
403+
const start = Date.now();
404+
debugger; // This will pause if DevTools is open
405+
const end = Date.now();
406+
return end - start > 100; // If more than 100ms passed, DevTools is likely open
407+
};
408+
409+
// Function to detect DevTools and take action
410+
const detectDevTools = () => {
411+
if (isDevToolsOpen() || detectDebugger()) {
412+
if (!devtoolsOpen) {
413+
devtoolsOpen = true;
414+
alert('Developer tools are open!');
415+
console.warn('Developer tools are open!');
416+
clearSensitiveData(clearSensitiveContent);
417+
overlayScreen(overlayId);
418+
}
419+
} else {
420+
if (devtoolsOpen) {
421+
devtoolsOpen = false;
422+
HideOverlayScreen(overlayId, clearSensitiveContent);
360423
}
361-
};
362-
// Run the check every second
363-
setInterval(detectDevTools, 1000);
364-
})();
424+
}
425+
};
426+
427+
// Initial check and setInterval to keep checking
428+
detectDevTools();
429+
setInterval(detectDevTools, 1000);
365430
}
366431

432+
367433
function handleTouchStart(event) {
368434
const now = new Date().getTime();
369435
const timeSinceLastTouch = now - lastTouchTime;
@@ -382,4 +448,3 @@ if (isNode) {
382448
}else{
383449
window.noScreenshot = noScreenshot;
384450
}
385-

0 commit comments

Comments
 (0)