2014-12-19 2 views
2

일부 웹 사이트는 위젯이있는 모든 페이지에서 Chrome 콘솔을 사용 중지합니다 (console.log가 작동하지 않음).웹 사이트를 사용 중지 한 후 Chrome 개발자 콘솔을 다시 사용하도록 설정하는 방법은 무엇인가요?

다시 사용하도록 설정 하시겠습니까? (해킹 등)

P.S. 내가 알기 론, 그들은 콘솔 기능을 다시 작성하는 것입니다. 그래서 내 질문은 기본적 으로이 : 다시 정상으로 재작 성하는 솔루션은 무엇입니까? (콘솔을 차단하는 것에 대한 나의 이해가 맞다면)

답변

2

다음은 사용할 수있는 해킹입니다. Chrome에서 사용하는 원래 Console 클래스로 재설정 할 수있는 방법이 없습니다. window.console = new Console(), 액세스 할 수없는 것 같습니다.

대신 다른 console 객체를 가져 와서 현재 window.console을 가리킬 필요가 있습니다. 가장 쉬운 방법은 숨겨진 iframe을 만들어서 사용하는 것입니다. 참고 iframe을 페이지에 유지해야합니다. 제거하면 console이 정리되고 완전히 작동하지 않습니다.

는 여기와 a working fiddle을 할 수있는 jQuery를 1 라이너의 :

var theFrame = document.createElement('iframe'); 
theFrame.src = "about:blank"; 
theFrame.style.display = "none"; 
document.body.appendChild(theFrame); 
window.console = theFrame.contentWindow.console; 

유일한 다른 일에 :

window.console = 
    $('<iframe src="about:blank" style="display:none;"/>') 
    .appendTo(document.body)[0].contentWindow.console; 

을 그리고 당신은 순수 JS 솔루션 (fiddle)를 원하는 경우 스택 조각이있는 것처럼 현재 페이지 자체가 sandbox 인 iframe에있는 경우 보안 오류가 발생하고 수행 할 수있는 일이 많지 않습니다. 그것에 대해. 그것은 단지 당신은 "다시 활성화"고 말했다 sandbox="allow-scripts"

// break the console 
 
window.console = { 
 
    log: function(x) { alert('haha I hijacked your console'); } 
 
} 
 

 
console.log('debug message'); 
 

 
var theFrame = document.createElement('iframe'); 
 
theFrame.src = "about:blank"; 
 
theFrame.style.display = "none"; 
 
document.body.appendChild(theFrame); 
 
window.console = theFrame.contentWindow.console; 
 

 
console.log('debug message');

0

을 가지고 있기 때문에

이 조각 [현재] 예를 들어 실행되지 않습니다. 어떻게해야할지 모르겠다. 반면에 페이지를 제어하면 처음부터 덮어 쓰지 않도록 할 수 있습니다. 이것이 먼저 실행되도록하십시오.

(function(origConsole) { 
    Object.defineProperty(window, 'console', { 
    get: function() { return origConsole; }, 
    set: function() {}, 
    enumerable: true, 
    configurable: false, 
    }); 
}(window.console)); 
(function(origLog) { 
    Object.defineProperty(window.console, 'log', { 
    get: function() { return origLog; }, 
    set: function() {}, 
    enumerable: true, 
    configurable: false, 
    }); 
}(window.console.log.bind(window.console))); 

은 어쩌면 확장

를 사용하여 주입
관련 문제