Firebug를 감지하는 Javascript?
사용자가 Firebug를 활성화했는지 확인하는 확실한 방법은 무엇입니까?
원래 답변 :
다음과 같이 console
객체 (Firebug로만 생성됨)를 확인합니다 .
if (window.console && window.console.firebug) {
//Firebug is enabled
}
업데이트 (2012 년 1 월) :
파이어 버그 개발자들은 한 제거하기로 결정했다window.console.firebug
. 다음 과 같이 덕 타이핑하여 Firebug의 존재를 감지 할 수 있습니다.
if (window.console && (window.console.firebug || window.console.exception)) {
//Firebug is enabled
}
또는 같은 다양한 다른 접근 방식
if (document.getUserData('firebug-Token')) ...
if (console.log.toString().indexOf('apply') != -1) ...
if (typeof console.assert(1) == 'string') ...
그러나 일반적으로 실제로 그렇게 할 필요는 없습니다.
방화범이 활성화 된 경우 window.console은 정의되지 않습니다. console.firebug는 버전 번호를 반환합니다.
Firebug 버전 1.9.0부터는 console.firebug
개인 정보 보호 문제로 인해 더 이상 정의되지 않습니다. 릴리스 노트 , 버그 보고서를 참조하십시오 . 이것은 위에서 언급 한 방법을 깨뜨립니다. 사실, 그것은 Allan의 질문에 대한 답을 "방법이 없다"로 변경합니다. 다른 방법 이 있으면 버그로 간주됩니다.
대신 해결책은 가용성 console.log
또는 사용하거나 교체하려는 것이 무엇인지 확인하는 것입니다.
다음은 David Brockman이 위에 제시 한 코드 종류에 대한 대체 제안이지만 기존 기능을 제거하지 않는 코드입니다.
(function () {
var names = ['log', 'debug', 'info', 'warn', 'error', 'assert', 'dir', 'dirxml',
'group', 'groupEnd', 'time', 'timeEnd', 'count', 'trace', 'profile', 'profileEnd'];
if (window.console) {
for (var i = 0; i < names.length; i++) {
if (!window.console[names[i]]) {
window.console[names[i]] = function() {};
}
}
} else {
window.console = {};
for (var i = 0; i < names.length; i++) {
window.console[names[i]] = function() {};
}
}
})();
감지가 불가능할 수 있습니다.
Firebug에는 개별적으로 비활성화 할 수있는 여러 탭이 있으며 이제 기본적으로 활성화되지 않습니다.
GMail은 "콘솔"탭을 활성화했는지 여부 만 알 수 있습니다. 이보다 더 멀리 탐색하려면 보안 우회가 필요할 수 있으며 거기에 가고 싶지 않습니다.
이와 같은 것을 사용하여 코드의 방화범 호출이 설치되지 않은 경우 오류가 발생하지 않도록 할 수 있습니다.
if (!window.console || !console.firebug) {
(function (m, i) {
window.console = {};
while (i--) {
window.console[m[i]] = function () {};
}
})('log debug info warn error assert dir dirxml trace group groupEnd time timeEnd profile profileEnd count'.split(' '), 16);
}
Chrome window.console에서도 true 또는 [ Object console]
.
또한 Firebug가 설치되었는지 확인합니다.
if (window.console.firebug !== undefined) // firebug is installed
아래는 내가 Safari와 Chrome에서 얻은 것입니다.
if (window.console.firebug) // true
if (window.console.firebug == null) // true
if (window.console.firebug === null) // false
Is-True 및 Is-Not 연산자는 JavaScript에서 피해야하는 유형 강제 변환을 수행합니다.
Currently, the window.console.firebug has been removed by latest firebug version. because firebug is an extension based JavaScript debugger, Which defined some new function or object in window.console. So most times, you can only use this new defined functions to detection the running status of firebug.
such as
if(console.assert(1) === '_firebugIgnore') alert("firebug is running!");
if((console.log+'''').indexOf('return Function.apply.call(x.log, x, arguments);') !== -1) alert("firebug is running!");
You may test these approach in each firebug.
Best wishes!
참고URL : https://stackoverflow.com/questions/398111/javascript-that-detects-firebug
'programing tip' 카테고리의 다른 글
React.js에서 Google 글꼴을 사용하는 방법은 무엇입니까? (0) | 2020.11.08 |
---|---|
GIL 때문에 다중 스레드 Python 코드에서 잠금이 필요하지 않습니까? (0) | 2020.11.08 |
이 다형성 C # 코드가 수행하는 작업을 인쇄하는 이유는 무엇입니까? (0) | 2020.11.08 |
Redis 키에서 콜론의 목적은 무엇입니까 (0) | 2020.11.08 |
JPA 기준 자습서 (0) | 2020.11.08 |