Beruflich Dokumente
Kultur Dokumente
Development.
Over the last few years there has been one tool that has helped out every web developer more than any other the browser developer tools. W orking in harmony with the web browser, the developer tools allows us to manipulate DOM elements, CSS styles, JavaSc ript and other useful information from the same window often in real time. Historically developers have used Firefoxs Firebug add -on to develop and debug their websites, but more recently each browser has developed its own set of tools and each comes with its own advantages and disadvantages. Nowadays it seems hard to imagine ever building a website without one of these handy tools, which are normally accessible by either pressing F12 in W indows or Cmd
Option
and I on the Mac, or by right clicking on the page and selecting Inspect Element.
Development Toolset Developer Tools Firebug Developer Toolbar Dragonfly Developer Tools
But are you using the developer tools to their full potential? The biggest positive about the developer tools is that they are incredibly easy to use, but as a result developers often miss out on a large proportion of the functionality provided. Inspired b y a video talk by Paul Irish and Pavel Feldman , Ive compiled a list of secrets of the developer console. Im not expecting every one of these to be unknown to you, but hopefully some of these will help you to become an even better web developer. If you have any more secrets, feel free to leave a co mment at the end of the article and Ill update the post once I have verified them. Id also love to know what developer console you use as your primary development tool, let me know below!
In Opera, you can select the previous element you had highlighted using $1. In Chrome and Safari, you can select the previous elements you have highlighted using $1 $4.
Using console.log to output multiple values and objects at the same time
All W e know console.log() is incredibly useful for outputting debug to the developer console, and preferred over alerts, but it can be irritating to output a string followed by an object if you re not aware of this feature of logging. Using console.log('message:' + $('#message')) will only tell you that your message is an object, and logging the object by its self can get confusing if the log is happening in the middle of a loop. console.log() actually accepts multiple parameters, so you can output both the string and the object from the same command using console.log('message:', $('#message')) ; or any other combination of JavaScript type you can think of. You can use console.warn() for warning messages; console.error() for error messaging and console.info() for information messages. You can also use console.assert() to test expressions for true or false. (Thanks to Masklinn for additional information)
Persist
Chrome, Firefox Theres an obvious button for persisting con sole content in Firefox right above the console, but its slightly more hidden in Chrome. Right click in the console to reveal a menu with Preserve Log upon Navigation as an option.
Changing frame
Firefox Running JavaScript commands from the console command line is incredibly useful, but if you have an iframe to contend with it quickly becomes a problem. Luckily you can use the following command to focus on the frame in question and execute your commands against.
cd(window.frames['frameName']);
Chrome Chrome allows you to change frame in a different way. On a page which contains frames, youll need to go to the Console tab and choose your frame from the dropdown at the bottom of the console.
Opera Opera also has a dropdown for changing frame which is available from the Console and Documents tab. The dropdown will only appear on the Console tab if there are frames to select.
(Thanks to Paul Irish and Daniel Herzog for the additional information)
In Internet Explorer 9, click the tool icon by the script selection drop down to find the option to format the JavaScript.
Watching variables
All A common tool with .NET development, watch allows you to monitor a list of variables from one handy area, at the top of t he right hand bar on the scripts tab. W atching a variable is really easy, just type in the name of the variable and watch will keep its value up to date.
Firebug, Internet Explorer, Opera Youll need to select the Layout tab in the right hand panel or scroll through the list of computed styles in the right hand sidebar. (Thanks to Masklinn for the additional information)
For Firebug, in the right hand column click the arrow menu beside the Style tab and selected your desired state. In Opera, its the icon that looks like a list under Styles.
Color picker
Opera In Opera, clicking the color square next to a color allows you to select a different color via a handy picker.
refresh. The tab is known as Net in Firefox. For Internet Ex plorer, it is only available in version 9 and later.
Latency
All In Chrome and Safari, the network tab allows you to see how long it takes a server to respond to a request. The faded color line for each resource indicates when the request was sent, and when a response was sent back. The filled color indicates when the resou rce was downloaded. In Chrome, you can hover over these lines to get a breakdown of where the time was spent. In Opera, the same principles apply except the latency is measured by a grey line as opposed to a faded line.
In Internet Explorer, latency is marked as yellow and hovering over the line will give more information. In Firebug, latency is marked in the color purple and labelled as W aiting. Hovering over one of these lines in Firebug also gives a detailed breakdown of where the time was spent.
Other Crashing
All Sometimes I find my developer tools have crashed and wont respond to m y mouse clicks. Rather than close the entire browser window and re-open, I often find that using the keyboard shortcuts to close and reopen the developer tools fixes the problem. I hope these features and secrets have been useful to you, although your skill level and experience will determine how many of these are new to you. I deliberately havent included profiling and remote debugging in this list, as these are topics I want to cover in more detail in a later post. Please feel free to leave feedback, corrections and your own tips below!