@@ -117,10 +117,11 @@ function noScreenshot(options, overlayId) {
117
117
document . addEventListener ( 'contextmenu' , event => event . preventDefault ( ) ) ;
118
118
119
119
// clear console every secound
120
- clearConsoleArea ( ) ;
121
-
120
+ if ( clearConsole ) {
121
+ clearConsoleArea ( ) ;
122
+ }
122
123
// detect if inspect element open
123
- detectInspectElement ( clearSensitiveContent ) ;
124
+ detectInspectElement ( clearSensitiveContent , overlayId ) ;
124
125
}
125
126
126
127
if ( disablePrintScreen ) {
@@ -205,7 +206,7 @@ function noScreenshot(options, overlayId) {
205
206
206
207
function escListener ( event ) {
207
208
if ( event . key === 'Escape' ) {
208
- HideOverlayScreen ( overlayId ) ;
209
+ HideOverlayScreen ( overlayId , clearSensitiveContent ) ;
209
210
// document.body.removeChild(overlay);
210
211
// document.body.style.pointerEvents = 'auto'; // Re-enable pointer events on body
211
212
//document.removeEventListener('keydown', escListener);
@@ -278,7 +279,7 @@ function overlayScreen(overlayId) {
278
279
}
279
280
280
281
281
- function HideOverlayScreen ( overlayId ) {
282
+ function HideOverlayScreen ( overlayId , clearSensitiveContent = false ) {
282
283
if ( overlayId ) {
283
284
const customOverlay = document . getElementById ( overlayId ) ;
284
285
if ( customOverlay ) {
@@ -290,13 +291,13 @@ function HideOverlayScreen(overlayId) {
290
291
return ;
291
292
}
292
293
}
294
+ if ( clearSensitiveContent ) {
295
+ location . reload ( ) ;
296
+ }
293
297
var overlay = document . getElementById ( 'no-screenshot-overlay' ) ;
294
298
document . body . removeChild ( overlay ) ;
295
299
document . body . style . pointerEvents = 'auto' ; // Re-enable pointer events on body
296
300
//document.removeEventListener('keydown', escListener);
297
- if ( clearSensitiveContent ) {
298
- location . reload ( ) ;
299
- }
300
301
}
301
302
302
303
@@ -327,43 +328,108 @@ function clearSensitiveData(selector) {
327
328
if ( element ) {
328
329
element . innerHTML = '' ;
329
330
}
331
+ } else {
332
+ const element = document . querySelector ( 'body' ) ;
333
+ element . innerHTML = '' ;
330
334
}
331
335
}
332
336
}
333
337
334
338
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 ) ;
360
423
}
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 ) ;
365
430
}
366
431
432
+
367
433
function handleTouchStart ( event ) {
368
434
const now = new Date ( ) . getTime ( ) ;
369
435
const timeSinceLastTouch = now - lastTouchTime ;
@@ -382,4 +448,3 @@ if (isNode) {
382
448
} else {
383
449
window . noScreenshot = noScreenshot ;
384
450
}
385
-
0 commit comments