Chrome에서 디버깅 할 때 스크립트 실행을 종료하는 방법은 무엇입니까?
Chrome 디버거에서 JavaScript 코드를 단계별로 실행할 때 계속하지 않으려면 어떻게 스크립트 실행을 종료합니까? 내가 찾은 유일한 방법은 브라우저 창을 닫는 것입니다.
"Reload this page"를 누르면 나머지 코드가 실행되고 F8 "Continue"를 누른 것처럼 양식을 제출합니다.
업데이트 :
스크립트가 일시 정지 된 상태에서 F5 (새로 고침)를 누르면 :
- Chrome (v22)은 스크립트를 실행합니다. 스크립트가 HTTP 요청을 제출하면 해당 요청에 대한 HTTP 응답이 표시됩니다. 원본 페이지가 새로 고쳐지지 않습니다.
- IE 9는 멈 춥니 다. 그러나 IE에는 "Stop Debugging"옵션이 있는데,이 버튼을 누르면 (F5를 누르지 않은 경우) 디버거 외부에서 스크립트를 계속 실행합니다.
- Firebug는 Chrome과 동일하게 작동합니다.
브라우저 창을 닫았다가 다시 여는 것이 브라우저 세션 상태를 종료시키고 중요 할 수 있기 때문에 항상 다음으로 가장 쉬운 방법은 아닙니다. 모든 중단 점도 손실됩니다.
업데이트 (2014 년 1 월) :
디버깅하는 동안 새로 고침 :
- Chrome v31 : 추가 중단 점에서 스크립트를 실행하고 중지 한 다음 (아약스 요청을 제출하지 않음) 새로 고칩니다.
- IE 11 : 새로 고침은 아무 것도 수행하지 않지만 F5 키를 눌러 계속할 수 있습니다.
- Firefox v26 : 스크립트 실행을 허용하지만 추가 중단 점에서 중지하지 않고 ajax 요청을 제출 한 다음 새로 고칩니다.
진보의 종류!
디버깅하는 동안 동일한 페이지로 이동하십시오.
- Chrome v31 : 새로 고침과 동일합니다.
- IE 11 : 스크립트가 종료되고 새 브라우저 세션이 시작됩니다 (닫았다가 다시 여는 것과 동일).
- Firefox v26 : 아무 일도 일어나지 않습니다.
또한 juacala 는 효과적인 해결 방법을 제안했습니다. 예를 들어, jQuery를 사용하는 경우 콘솔에서 delete $ 를 실행하면 jQuery 메소드가 발견되면 실행이 중지됩니다. 위의 모든 브라우저에서 테스트했으며 작동하는지 확인할 수 있습니다.
업데이트 (2015 년 3 월) :
마지막으로 2 년이 넘고 거의 10 만 회의 조회 한 후에 Alexander K가 정답을 제시했습니다. Chrome에는 자체 작업 관리자가 있어 탭 자체 를 닫지 않고도 탭 프로세스 를 종료하여 모든 중단 점 및 기타 사항을 그대로 유지할 수 있습니다.
Chrome v22에서 브라우저를 테스트하기 위해 BrowserStack.com까지 갔으며 그 당시에도 이런 방식으로 작동한다는 것을 알았습니다.
Juacala의 해결 방법은 IE 또는 Firefox에서 디버깅 할 때 여전히 유용합니다.
업데이트 (2019 년 1 월) :
Chrome 개발자 도구는 마침내 스크립트 실행을 중지하는 적절한 방법을 추가했습니다 (약간 숨겨져 있지만). 자세한 내용은 James Gentes의 답변을 참조하십시오.
Chrome에는 "작업 관리자"가 있으며 Shift+ ESC또는
메뉴 → 추가 도구 → 작업 관리자
"작업 끝내기"버튼을 눌러 페이지 작업을 선택하고 종료 할 수 있습니다.
현재 2018년 4월, 당신은 크롬에서 무한 루프를 중지 할 수 있습니다 :
- 오픈 소스 개발자 도구 패널 ( I + Ctrl 키 + 시프트 ).
- 스크립트 실행 을 일시 중지 하려면 일시 중지 버튼을 클릭하십시오 .
바로 가기 키도 참고하십시오 : F8 및 Ctrl + \
이를 수행 할 수있는 한 가지 방법은 스크립트를 일시 중지하고 현재 중지 된 곳에서 어떤 코드가 뒤에 오는지 확인하는 것입니다. 예 :
var something = somethingElse.blah;
콘솔에서 다음을 수행하십시오.
delete somethingElse;
그런 다음 스크립트를 재생하십시오. 액세스하려고하면 치명적인 오류가 발생 somethingElse
하고 스크립트가 종료됩니다. Voila, 당신은 스크립트를 종료했습니다.
편집 : 원래 변수를 삭제했습니다. 충분하지 않습니다. JavaScript가 속성에 액세스하려고하는 함수 또는 객체를 삭제해야합니다.
@scottndecker의 다음 질문에 대한 답변을 참조 하면 Chrome은 이제 개발자 도구에서 'JavaScript 비활성화'옵션을 제공합니다.
...
오른쪽 상단의 세로- 설정
- '환경 설정'에서 맨 아래의 '디버거'섹션으로 이동하여 'JavaScript 비활성화'를 선택하십시오.
Good thing is you can stop and rerun again just by checking/unchecking it.
Good question here. I think you cannot terminate the script execution. Although I have never looked for it, I have been using the chrome debugger for quite a long time at work. I usually set breakpoints in my javascript code and then I debug the portion of code I'm interested in. When I finish debugging that code, I usually just run the rest of the program or refresh the browser.
If you want to prevent the rest of the script from being executed (e.g. due to AJAX calls that are going to be made) the only thing you can do is to remove that code in the console on-the-fly, thus preventing those calls from being executed, then you could execute the remaining code without problems.
I hope this helps!
P.S: I tried to find out an option for terminating the execution in some tutorials / guides like the following ones, but couldn't find it. As I said before, probably there is no such option.
http://www.codeproject.com/Articles/273129/Beginner-Guide-to-Page-and-Script-Debugging-with-C
http://www.nsbasic.com/app/tutorials/TT10.htm
If you are encountering this while using the debugger
statement,
debugger;
... then I think the page will continue running forever until the js runtime yields, or the next break. Assuming you're in break-on-error mode (the pause-icon toggle), you can ensure a break happens by instead doing something like:
debugger;throw 1;
or maybe call a non-existent function:
debugger;z();
(Of course this doesn't help if you are trying to step through functions, though perhaps you could dynamically add in a throw 1
or z()
or somesuch in the Sources panel, ctrl-S to save, and then ctrl-R to refresh... this may however skip one breakpoint, but may work if you're in a loop.)
If you are doing a loop and expect to trigger the debugger
statement again, you could just type throw 1
instead.
throw 1;
Then when you hit ctrl-R, the next throw will be hit, and the page will refresh.
(tested with Chrome v38, circa Apr 2017)
You can do it, but you must prepare your code first.
Instructions for halting script execution in Google Chrome Dev Tools:
(1) Prepare your code first, by creating a global variable:
var devquit=0;
$(document).ready({
//the rest of your code
(2) Any place where you may wish to quit, test the value of this variable:
//Lotsa code
if (devquit > 0) return false;
(3) Pause execution of script on-or-before the above test line(s)
(4) Switch to console
(5) Type:
> devquit
0
> devquit=1 <=== only this line is necessary
> devquit
1
(6) Continue script execution. Script will return false
when it executes the test from step (2) above
Notes:
(A) This trick works with global variables and objects, but it will not work with local variables. Note that this:
newVar = 'never used before';
creates a new property of the window object (works with above trick), whilst this:
var newVar = 'never used before';
creates a local variable (does NOT work with above trick!)
(B) So, you can still use this trick with already-running code if you have either a global variable or an object that will return false if it has a given value.
(C) In a pinch, you can use juacala's trick and delete an element from the DOM (on the elements tab) that will cause a javascript error. For example, suppose you have code var cartype = $('#cartype').val();
If you delete the element with ID=cartype
before that line of code, then the js will break on that line. However, the element will still be missing when you try to re-run the code. The trick described above allows you to run and re-run the code ad infinitum.
More notes:
(a) Insert breakpoint into code: just type debugger;
on a line by itself. If DevTools is open, the script will jump into debugger at that point. If DevTools not open, code will ignore statement.
(b) Want to avoid jumping into the jQuery library when debugging code? Blackbox it. See blackbox instructions for Chrome - or - for Firefox
Gratitude (please visit and upvote):
Javascript Debugging line by line using Google Chrome
Is it possible to change javascript variable values while debugging in Google Chrome?
If you have a rogue loop, pause the code in Google Chrome debugger (the small "||
" button while in Sources tab).
Switch back to Chrome itself, open "Task Manager" (Shift+ESC), select your tab, click the "End Process" button.
You will get the Aww Snap message and then you can reload (F5).
As others have noted, reloading the page at the point of pausing is the same as restarting the rogue loop and can cause nasty lockups if the debugger also then locks (in some cases leading to restarting chrome or even the PC). The debugger needs a "Stop" button. Nb: The accepted answer is out of date in that some aspects of it are now apparently wrong. If you vote me down, pls explain :).
Open the source tab in 'Developer Tools', click on a line number in a script that is running, this will create a breakpoint and the debugger will break there.
You can pause on any XHR pattern which I find very useful during debugging these kind of scenarios.
For example I have given breakpoint on an URL pattern containing "/"
이 게시물에서 위에서 언급 한 것처럼이 문제에 대한 적절한 해결책이 많이 있지만 스크립트에서 삽입하거나 Chrome 콘솔 (디버거)에 붙여 넣을 수있는 작은 해킹을 발견했습니다.
jQuery(window).keydown(function(e) { if (e.keyCode == 123) debugger; });
이렇게하면를 누를 때 실행이 일시 중지됩니다 F12
.
대부분의 경우 페이지의 요소를 변경하고 검사하지 못하게하는 루프 또는 타이머를 중지하려고합니다 ...
대부분 jQuery를 사용하므로 다음을 사용합니다.
jQuery 삭제
'IT' 카테고리의 다른 글
Pylint가 올바르지 않은 것으로 간주하는 조건 값에서 len (SEQUENCE)을 사용하는 이유는 무엇입니까? (0) | 2020.05.14 |
---|---|
편안한 POST 응답을위한 '최상의'실습 (0) | 2020.05.14 |
대상이 최신이라고 생각하는 이유는 무엇입니까? (0) | 2020.05.13 |
mysql에서“잘못된 조합의 데이터 정렬”오류 문제 해결 (0) | 2020.05.13 |
__getattr__과 __getattribute__의 차이점 이해 (0) | 2020.05.13 |