Firebug 571
Firebug 571
When copying any JavaScript code from these slides, the console might return the following:
Outline
What is Firebug? Why do web developers use Firebug? Installation of Firebug for Mozilla Firefox browser Launching Firebug for the First Time The Panels of Firebug Firebug Tutorials
What is Firebug?
Firebug is an extension for the Mozilla Firefox browser that allows you to debug and inspect HTML, CSS, the Document Object Model (DOM) and JavaScript.
INTRODUCTION
INTRODUCTION
OR
2) Press the Firebug button on the toolbar (By default, body HTMLElement is selected)*
*Note: Firebug may continue from a last saved session if it is still running
INTRODUCTION
INTRODUCTION
Hello, Firebug!
FIREBUG TOOLBAR
Lets take a look at the Firebug Toolbar first, as we will use this throughout the tutorial. HTML PANEL
Firebug Toolbar
PANELS
Console: Brings up a Interactive JavaScript Console HTML: Brings up the HTML View (see previous) CSS: Brings up the CSS View Script: Brings up the JavaScript Debugger (used later) DOM: A list of all the DOM Properties (defaults to window object) Net: Displays requests made from the browser Cookies: Displays sessions & cookies from the browser
FIREBUG TOOLBAR
FIREBUG TOOLBAR
FIREBUG TOOLBAR
1) Use the Inspect Element feature in Firebug. (Right click on the element, and click on Inspect Element with Firebug)
Note: We can also use this button and click on the element INSPECTING HTML/CSS ELEMENTS AND THEIR PROPERTIES
From the highlighted area, we know the following about the element:
<a class=btn btn-primary btn-large>Im a cool button.</a> INSPECTING HTML/CSS ELEMENTS AND THEIR PROPERTIES
BREADCRUMB
From the highlighted area & the breadcrumb we know the following about the element:
<a 1. 2. 3. 4.
class=btn btn-primary btn-large>Im a cool button.</a> The element is an anchor The element has a class attribute btn btn-primary btn-large The element has a TextNode with TextContent Im a cool button The elements parent node is body (whose parent node is html)
Theres a lot more we can say about the element though! INSPECTING HTML/CSS ELEMENTS AND THEIR PROPERTIES
Notice: We have an attributes member variable, which has an array of attributes. This is another way how to determine the attributes for the selected element.
1A
Tip: Clicking on the +/- displays the computation for the CSS property
(Cascaded properties are crossed out)
Tutorial 1 Summary
TUTORIAL OBJECTIVES 1) Find out the attributes & DOM properties of the element Solution: In the HTML Panel, click DOM on the right side pane.
2) Find out the computed CSS properties Solution: In the HTML Panel, click DOM on the right side pane
3) Draw the box model for the element. Solution: In the HTML Panel, click on Layout
Tutorial 1 Summary
TUTORIAL OBJECTIVES 4) Determining CSS Hover Properties of the element Solution: Hover over the element, watch the Style pane in HTML View
HOW IS THIS USEFUL? 1) Can visualize how an element is formed in CSS/HTML/JavaScript Example A client of yours likes a button at Google+. The client wants that same exact button in their web application. Time to use Firebug.
TO
WHAT WE WILL LEARN How to change the view of an element in real time in the browser, even though we dont have access rights to modifying the file. MODIFYING THE DOM OF AN ELEMENT IN REAL TIME
Method 1: Using the HTML View & Style Pane 1) Launch Firebug and under the HTML View inspect the body element. - Easy way to do this: F12, click on the body tag. It is highlighted.
Hovering over the element does 2 things: 1) shows an info box about the property (if available) 2) Clicking on will hide the selected property.
MODIFYING THE DOM OF AN ELEMENT IN REAL TIME
Method 1: Using the HTML View & Style Pane 2) Click on the braces { } of the CSS element declaration. Firebug will allow you to add a new css property.
3) Add the following properties: Result but we are not done yet
4) Inspect the paragraph element, I am a paragraph element with black text and a white background
CONSOLE PANEL
2 1. The Interactive JavaScript Console. All console messages (console.log), output of execution is displayed here. 2. Write commands here. As long the JavaScript is valid, any command here will be executed in real time. 3. Filtering. We can filter messages by their type. Clicking will cause the console to break on all errors. MODIFYING THE DOM OF AN ELEMENT IN REAL TIME
Neat! Firebug has autocomplete when typing in JavaScript commands What did we just do? We just set the text color of the body element to white, so currently we have white text on a white background (the border is there just to emphasize there is nothing)
document.body.style.backgroundColor = black; document.body.children[0].innerHTML = "I am a paragraph with white text and a black background;
TO
HOW WE ACCOMPLISHED THE OBJECTIVE WITH FIREBUG WITH 2 METHODS:
1. Method 1: Changing HTML/CSS Properties using the HTML Panel and the CSS Pane Solution: Use the CSS Pane to change the background to black and the text-color, to white Solution: Use the HTML pane to change the text content of the element
Method 2: Use the Interactive JavaScript Console Solution: Write JavaScript DOM object code in the Console (document.body.style.color.)
2.
var array = [Harman, Goei, CSCI, 571]; for(var i = 0; i < array.length; i++) { console.log(array[i]); }
Instead of writing line by line, we can the entire block in the console. Heres how:
1. Press the
3. Click Run.
1. Step through the behavior of the JavaScript code 2. Understand what happens in the console when JavaScript hits an error
We will be analyzing the following JavaScript: var array = [1,2,3,4,5,6,7,8, "9"]; WHAT THE CODE DOES 1. Given an array, add 1 to each element. 2. In 5 seconds, a function will do an illegal operation in JavaScript.
for(var i = 0; i < array.length; i++) { array[i] = array[i] + 1; } console.log(array); setTimeout(function() { x=z; }, 5000);
QUESTION: Why did the last element become 91? We will analyze this by stepping through the code. 3) Click on Script
1. The Script Panel View 2. Actions when JavaScript has hit a breakpoint 1. Rerun Shift + F8 2. Continue F8 3. Step Into F11 4. Step Over F10 5. Step Out Shift F11 UNDERSTANDING BEHAVIOR OF JAVASCRIPT CODE & DETECTING ERRORS WITH FIREBUG
5) JavaScript has stopped on the breakpoint. Notice: The page is still loading because the body element is not loaded. UNDERSTANDING BEHAVIOR OF JAVASCRIPT CODE & DETECTING ERRORS WITH FIREBUG
6) We can execute JavaScript code while JavaScript is still in the breakpoint. Hit UNDERSTANDING BEHAVIOR OF JAVASCRIPT CODE & DETECTING ERRORS WITH FIREBUG
setTimeout(function() { x=z; console.log(Hello there!); }, 5000); UNDERSTANDING BEHAVIOR OF JAVASCRIPT CODE & DETECTING ERRORS WITH FIREBUG
WHY IS THIS USEFUL? By default, JavaScript code stops executing from the line an error occurs. If we didnt have Firebug, we would expect Hello there! to appear in the console, but it didnt, and we would debug manually by using alert() or document.write()
1
1. The requests made 2. Filtering
1. There were 15 requests, 273.5 KB in total size, 243.3 KB from cache. 2. The remote IP is 74.125.239.18: 443 and 74.125.224.162:443 for one req. 3. The status of each request, and what type it was
DETECTING WEB PERFORMANCE USING FIREBUG
4. The longest request is 297 ms. 5. We also know the timeline of each request 6. The legend on the right indicates what each request was doing
TIP: Hovering over an image will show an info box of the image
1) Expand the request by clicking on +
WHY IS ANALYZING PERFORMANCE WITH FIREBUG USEFUL? We can detect how large a request is, and where the website is really slow - which is how we can improve performance for a site
1. Name and Expand button. Expanding the cookie only reveals the full value of the value attribute. 2. Value of the cookie 3. Domain of the cookie 4. The size 5. The path 6. When it expires / or whether it is a session
Sources
(Used for Introduction) SitePoint Firebug CSS Active Hover States - http://www.sitepoint.com/firebugcss-active-hover-states/ - Tip for :hover Firebug - https://getfirebug.com/ (Images, and Firebug Console)
Tutorials were made from scratch, based on my real-life scenarios as a web developer:
Tutorial 1: Client: I really like this button from http://www.google.com . I want that same button on my website. Tutorial 2: Client: Can we compare how the website looks with white text and black background, black background & white text? Tutorial 3: When I was developing a canvas application for USC Viterbi, I was adding numbers like the following: 2 + 2. I expected 4, but the result turned out to be 22. Tutorial 4: When I had the lecture in CSCI 571 about Web Performance, I played with Firebug Tutorial 5: Internship made me deal with cookies/sessions