Access last logged value in Chrome console
When I evaluate an expression directly in the Chrome Console like
1 + 1
then I can reference to the evaluated value using
$_
However, I can't access the value with $_, when the value is a result of a console.log, coming from inside of my application, instead of an expression I typed directly into the console.
Is there a way to access the last evaluated expression, regardless where it came from?
After it's been logged to the console, you can right click on it and get an option to Store as global function. Clicking this will define a new variable like 'temp1' which will point to the variable. Here's a video of it in action (not mine).
Just follow these steps:
- Click over the result with right button
- Save as global variable
- copy(temp1)
You can only copy & paste.
See all available commands and shortcuts:
https://developers.google.com/chrome-developer-tools/docs/commandline-api https://developers.google.com/chrome-developer-tools/docs/shortcuts
A work-around for this is to define a variable in the global namespace. Presumably, your console.log(local_variable)
is inside a function.
<script>
var global_variable = null;
function some_function() {
var local_variable = 0;
global_variable = local_variable;
console.log(local_variable);
}
</script>
Here, when some_function()
is called, your local_variable
will be logged, but you can then type global_variable
in your console to get its value quickly and work with it.
You could access any evaluated expression at any point in execution with Chrome's DevTools by setting breakpoints.
Your logged expression should have a clickable line number in the console - follow the link, then set a breakpoint on the line of code (which should be your console.log
).
Full guide on breakpoints:
https://developers.google.com/web/tools/chrome-devtools/javascript/breakpoints
I think $0
is what you're looking for.
참고URL : https://stackoverflow.com/questions/15895579/access-last-logged-value-in-chrome-console
'Programing' 카테고리의 다른 글
Google Firestore-한 번의 왕복으로 여러 ID로 문서를 얻는 방법은 무엇입니까? (0) | 2020.12.02 |
---|---|
OpenGL을 디버깅하는 가장 좋은 방법은 무엇입니까? (0) | 2020.12.02 |
memset이 정수 배열을 -1로 초기화하는 방법은 무엇입니까? (0) | 2020.12.02 |
Python에서 예외 메시지를 올바르게 얻는 방법 (0) | 2020.12.02 |
ASP.NET MVC에서 ETag를 어떻게 지원합니까? (0) | 2020.12.02 |