I would like to use this blog to record the tips of using Chrome development tool in my daily UI5 application development life.
The version of my Chrome is: 49.0.2623.54 beta-m (64-bit).
In Source tab, select the source file, for example "jquery.sap.act-dbg.js", press Ctrl+G, type ":<the line number which you want to navigate>", press enter key:
Destination reached:
Click Sources->Sources, press Ctrl+O and type the file name character by character. Automatic completion is supported and thus very convenient to search.
By default when you click the small triangle icon in Elements tab,
only its direct children node will be expanded:
Use Alt + Click to expand ALL its children.
Suppose you only want to select the content after "||" in line 1476 ~ 1477. By default it is not possible.
You can first press Alt, and then perform your selection as usual ( by dragging mouse ).
It is then done:
Suppose you use "Elements" tab to inspect the html tag of a given UI control instance:
You can simply type "$0" in console tag to get its reference:
And could directly modify its attribute in console and change will immediately take effect after enter key is pressed:
Still use the $0 in tip #5 for example. In console tab the command copy($0) will put all the source code of this html tag to the clipboard in your laptop,
so that you can just click Ctrl + C to get it in other place:
And command values will get all the attributes values of current object and display it as array:
For sure you can use both in chained style:
Suppose for trouble shooting, or research or whatever other reasons you would like to execute several lines of code, you could select them and press Ctrl+Shift+E. I just use line 107 ~ 11 below as an example.
Once pressed, those codes will automatically be pasted to Console tab and executed. The result is also displayed there.
Suppose you are debugging your code and you could like to save the callstack how your function is called for further research,
for example you would like to save the following callstack information into a text file:
You can just type "console.trace" in Console tab and then you can export the callstack information via Ctrl+C and Ctrl+V .
For trouble shooting purpose UI5ers like to use console.log to print useful traces however the trace printed by ourselves can easily be lost in the huge ones printed by jQuery.sap.log.debug when the application is running under debug mode. Have you ever considered to make your console.log generating completely different layout so that they could be identified at a first glance?
Paste the following source code into a local test.html file:
<html>
<script>
function myLog(text){
var textWithFormat = "%c" + text;
console.log( textWithFormat," text-shadow: 0 1px 0 #ccc,0 2px 0 #c9c9c9,0 3px 0 #bbb,0 4px 0 #b9b9b9,0 5px 0 #aaa,0 6px 1px rgba(0,0,0,.1),0 0 5px rgba(0,0,0,.1),0 1px 3px rgba(0,0,0,.3),0 3px 5px rgba(0,0,0,.2),0 5px 10px rgba(0,0,0,.25),0 10px 10px rgba(0,0,0,.2),0 20px 20px rgba(0,0,0,.15);font-size:5em")
}
myLog("Hello, World!");
myLog("Have fun!");
</script>
</html>
And you will get this output:
The format option "%c" tells the console.log to use the CSS style passed in via the second parameter.
More options are listed below:
Another example:
function myLogWithColor(text) {
console.log("%c" + text,"background: rgba(252,234,187,1);background: -moz-linear-gradient(left, rgba(252,234,187,1) 0%, rgba(175,250,77,1) 12%, rgba(0,247,49,1) 28%, rgba(0,210,247,1) 39%,rgba(0,189,247,1) 51%, rgba(133,108,217,1) 64%, rgba(177,0,247,1) 78%, rgba(247,0,189,1) 87%, rgba(245,22,52,1) 100%);background: -webkit-gradient(left top, right top, color-stop(0%, rgba(252,234,187,1)), color-stop(12%, rgba(175,250,77,1)), color-stop(28%, rgba(0,247,49,1)), color-stop(39%, rgba(0,210,247,1)), color-stop(51%, rgba(0,189,247,1)), color-stop(64%, rgba(133,108,217,1)), color-stop(78%, rgba(177,0,247,1)), color-stop(87%, rgba(247,0,189,1)), color-stop(100%, rgba(245,22,52,1)));background: -webkit-linear-gradient(left, rgba(252,234,187,1) 0%, rgba(175,250,77,1) 12%, rgba(0,247,49,1) 28%, rgba(0,210,247,1) 39%, rgba(0,189,247,1) 51%, rgba(133,108,217,1) 64%, rgba(177,0,247,1) 78%, rgba(247,0,189,1) 87%, rgba(245,22,52,1) 100%);background: -o-linear-gradient(left, rgba(252,234,187,1) 0%, rgba(175,250,77,1) 12%, rgba(0,247,49,1) 28%, rgba(0,210,247,1) 39%, rgba(0,189,247,1) 51%, rgba(133,108,217,1) 64%, rgba(177,0,247,1) 78%, rgba(247,0,189,1) 87%, rgba(245,22,52,1) 100%);background: -ms-linear-gradient(left, rgba(252,234,187,1) 0%, rgba(175,250,77,1) 12%, rgba(0,247,49,1) 28%, rgba(0,210,247,1) 39%, rgba(0,189,247,1) 51%, rgba(133,108,217,1) 64%, rgba(177,0,247,1) 78%, rgba(247,0,189,1) 87%, rgba(245,22,52,1) 100%);background: linear-gradient(to right, rgba(252,234,187,1) 0%, rgba(175,250,77,1) 12%, rgba(0,247,49,1) 28%, rgba(0,210,247,1) 39%, rgba(0,189,247,1) 51%, rgba(133,108,217,1) 64%, rgba(177,0,247,1) 78%, rgba(247,0,189,1) 87%, rgba(245,22,52,1) 100%);filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fceabb', endColorstr='#f51634', GradientType=1 );font-size:5em");
}
myLogWithColor("Hello, World!");
myLogWithColor("Have fun!");
Output:
function myLogWithRainbow(text) {
console.log('%c' + text, 'background-image:-webkit-gradient( linear, left top, right top, color-stop(0, #f22), color-stop(0.15, #f2f), color-stop(0.3, #22f), color-stop(0.45, #2ff), color-stop(0.6, #2f2),color-stop(0.75, #2f2), color-stop(0.9, #ff2), color-stop(1, #f22) );color:transparent;-webkit-background-clip: text;font-size:5em;');
}
myLogWithRainbow("Hello, World!");
myLogWithRainbow("Have fun!");
var _log = console.log;
console.log = function() {
_log.call(console, '%c' + [].slice.call(arguments).join(' '), 'color:transparent;text-shadow:0 0 2px rgba(0,0,0,.5);');
};
And now the normal "Hello world" will be displayed as below:
For self study purpose I am eager to know in which line of code in angular.js those comments are created, however I cannot set breakpoint on the native function createComment.
How to proceed then?
1. Set a breakpoint on the first line of angular.js, launch the html page, breakpoint is triggered:
2. Copy the following JavaScript code into console and type enter to execute it. Now the native function createComment is injected by these source code: every time it is called in Angular.js, the injected source code will be executed instead.
3. All the left task for me is to continue debug and debugger is triggered automatically when Angular.js calls createComment with a value containing string "ngRepeat".
This is just what I am looking for :smile:
(function(console){
console.save = function(data, filename){
if(!data) {
console.error('Console.save: No data')
return;
}
if(!filename) filename = 'console.json'
if(typeof data === "object"){
data = JSON.stringify(data, undefined, 4)
}
var blob = new Blob([data], {type: 'text/json'}),
e = document.createEvent('MouseEvents'),
a = document.createElement('a')
a.download = filename
a.href = window.URL.createObjectURL(blob)
a.dataset.downloadurl = ['text/json', a.download, a.href].join(':')
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
a.dispatchEvent(e)
}
})(console)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
12 | |
11 | |
10 | |
10 | |
8 | |
6 | |
6 | |
6 | |
5 | |
5 |