DefenseDebugger

coderljw 2024-10-13 Utils
  • Utils
  • DefenseDebugger
小于 1 分钟

# 1. 跳转空白页

export const gotoBlankPage = () => {
  const a = document.createElement("a");
  a.href = "about:blank";
  a.click();
};
1
2
3
4
5

# 2. 判断是否调试

  • 通过代码执行时间判断
export const isDebugger = (timeout = 30) => {
  const startTime = Date.now();
  debugger;
  return Date.now() - startTime > timeout;
};
1
2
3
4
5

# 3. 防止调试

export const defenseDebugger = (timeout = 30) => {
  const timer = window.setInterval(() => {
    if (isDebugger(timeout)) gotoBlankPage();
  }, timeout);

  return () => window.clearInterval(timer);
};
1
2
3
4
5
6
7
以父之名
周杰伦.mp3