feat: 规避ios移动端chrome误伤
This commit is contained in:
parent
db665cc1dc
commit
00c689e0b7
@ -2,7 +2,7 @@
|
||||
* @Author: tackchen
|
||||
* @Date: 2021-11-15 22:26:57
|
||||
* @LastEditors: tackchen
|
||||
* @LastEditTime: 2021-11-15 23:48:53
|
||||
* @LastEditTime: 2022-01-05 09:02:19
|
||||
* @FilePath: /disable-devtool/src/detector/date-to-string.js
|
||||
* @Description: Coding something
|
||||
*/
|
||||
@ -11,7 +11,8 @@ import {registInterval} from '../utils/interval';
|
||||
import {DETECTOR_TYPE, triggerOnDevOpen} from './detector';
|
||||
import {clearLog, log} from '../utils/log';
|
||||
|
||||
export default function detector () {
|
||||
export default function detector (isTrueIOSChrome) {
|
||||
if (isTrueIOSChrome) return;
|
||||
let count = 0;
|
||||
const date = new Date();
|
||||
date.toString = () => {
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @Author: tackchen
|
||||
* @Date: 2021-11-15 22:26:57
|
||||
* @LastEditors: tackchen
|
||||
* @LastEditTime: 2021-11-15 23:49:00
|
||||
* @LastEditTime: 2022-01-05 09:06:30
|
||||
* @FilePath: /disable-devtool/src/detector/debugger.js
|
||||
* @Description: Coding something
|
||||
*/
|
||||
@ -10,12 +10,15 @@
|
||||
import {registInterval} from '../utils/interval';
|
||||
import {DETECTOR_TYPE, triggerOnDevOpen} from './detector';
|
||||
|
||||
export default function detector () {
|
||||
registInterval(() => {
|
||||
const date = Date.now();
|
||||
(() => {debugger;})();
|
||||
if (Date.now() - date > 100) {
|
||||
triggerOnDevOpen(DETECTOR_TYPE.DEBUGGER);
|
||||
}
|
||||
});
|
||||
export default function detector (isTrueIOSChrome) {
|
||||
if (isTrueIOSChrome) {
|
||||
// 仅在 ios chrome 下生效
|
||||
registInterval(() => {
|
||||
const date = Date.now();
|
||||
(() => {debugger;})();
|
||||
if (Date.now() - date > 100) {
|
||||
triggerOnDevOpen(DETECTOR_TYPE.DEBUGGER);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
* @Author: theajack
|
||||
* @Date: 2021-07-24 23:16:34
|
||||
* @LastEditor: theajack
|
||||
* @LastEditTime: 2021-12-24 15:17:10
|
||||
* @LastEditTime: 2022-01-05 12:38:04
|
||||
* @Description: Coding something
|
||||
*/
|
||||
|
||||
@ -12,12 +12,11 @@ import DefineIdDetector from './define-id';
|
||||
import SizeDetector from './size';
|
||||
import DateToStringDetector from './date-to-string';
|
||||
import FuncToStringDetector from './func-to-string';
|
||||
// import DebuggerDetector from './debugger'; // 会debuger显示devtool
|
||||
// import LogTimeDetector from './log-time'; // 不准确 容易误伤
|
||||
import DebuggerDetector from './debugger';
|
||||
// import LogTimeDetector from './log-time'; // 不准确 容易误伤 故弃用
|
||||
import {clearDDInterval, clearDDTimeout} from '../utils/interval';
|
||||
import {closeWindow} from '../utils/close-window';
|
||||
|
||||
const detectorList = [];
|
||||
import {isIOSChrome, isLogRegExpCount3} from '../utils/util';
|
||||
|
||||
export const DETECTOR_TYPE = {
|
||||
UNKONW: -1,
|
||||
@ -37,19 +36,23 @@ const Detectors = {
|
||||
[DETECTOR_TYPE.DATE_TO_STRING]: DateToStringDetector,
|
||||
[DETECTOR_TYPE.FUNC_TO_STRING]: FuncToStringDetector,
|
||||
// [DETECTOR_TYPE.DEBUGGER]: DebuggerDetector,
|
||||
// [DETECTOR_TYPE.LOG_TIME]: LogTimeDetector,
|
||||
};
|
||||
|
||||
export function registDetector (detector) {
|
||||
detectorList.push(detector);
|
||||
}
|
||||
export async function initDetectors () {
|
||||
// ! 判断是否是 ios chrome 真机, true时 禁用 date 和 func detector,因为会误伤。启用debugger detector兜底
|
||||
const isTrueIOSChrome = isIOSChrome && (await isLogRegExpCount3());
|
||||
|
||||
export function initDetectors () {
|
||||
const typeArray = config.detectors === 'all' ?
|
||||
Object.keys(Detectors) : config.detectors;
|
||||
|
||||
if (isTrueIOSChrome) {
|
||||
typeArray.push(DebuggerDetector); // 会debuger显示devtool, 仅在ios chrome 真机生效
|
||||
}
|
||||
|
||||
typeArray.forEach(type => {
|
||||
if (Detectors[type]) {
|
||||
Detectors[type]();
|
||||
Detectors[type](isTrueIOSChrome);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -2,16 +2,19 @@
|
||||
* @Author: tackchen
|
||||
* @Date: 2021-11-15 22:26:57
|
||||
* @LastEditors: tackchen
|
||||
* @LastEditTime: 2021-11-15 23:49:07
|
||||
* @LastEditTime: 2022-01-05 08:08:02
|
||||
* @FilePath: /disable-devtool/src/detector/func-to-string.js
|
||||
* @Description: Coding something
|
||||
*/
|
||||
|
||||
// // ! 会误伤ios mobile chrome 可能会误伤谷歌搜索seo 故放弃使用
|
||||
|
||||
import {registInterval} from '../utils/interval';
|
||||
import {DETECTOR_TYPE, triggerOnDevOpen} from './detector';
|
||||
import {log, clearLog} from '../utils/log';
|
||||
|
||||
export default function detector () {
|
||||
export default function detector (isTrueIOSChrome) {
|
||||
if (isTrueIOSChrome) return;
|
||||
let count = 0;
|
||||
const func = () => {};
|
||||
func.toString = () => {
|
||||
|
@ -1,3 +1,5 @@
|
||||
import {log} from './log';
|
||||
|
||||
export function isPC () {
|
||||
return !/(iphone|ipad|ipod|ios|android)/i.test(navigator.userAgent.toLowerCase());
|
||||
}
|
||||
@ -104,3 +106,26 @@ export const isMacOs = hasUaName('macintosh');
|
||||
export const isOldEdge = hasUaName('edge') && !hasUaName('chrome');
|
||||
|
||||
export const isIE = isOldEdge || hasUaName('trident') || hasUaName('msie');
|
||||
|
||||
export const isIOSChrome = hasUaName('crios');
|
||||
|
||||
// ios chrome log regExp count=3 , 以此区别真机和开发者工具模拟的
|
||||
export async function isLogRegExpCount3 () {
|
||||
let count = 0;
|
||||
const target = new RegExp();
|
||||
target.toString = () => {
|
||||
count ++;
|
||||
return '';
|
||||
};
|
||||
log(target);
|
||||
await delay(100);
|
||||
return count === 3;
|
||||
}
|
||||
|
||||
export function delay (time = 1000) {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, time);
|
||||
});
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user