SlideShare a Scribd company logo
1 of 21
Javascript Debugging
Agenda
•   Browser-Specific Tools
     o IE 6/7: MS Script Debugger, MS Script Editor, MS Visual Studio (also IE Dev Toolbar)
     o IE 8: Developer Tools
     o Safari: Web Inspector
     o Chrome: Dev Tools (JS Console, DOM Inspector)
     o FireFox: Firebug
•   General Tools
     o YUI Logger
     o Alerts, prompts, and console.log()
     o JSLint
•   Common Pitfalls
     o Suppressed errors
     o Trailing commas in IE
     o Conflicting XHR requests
•   Using a Debugger
     o Step In/Over/Out
     o Breakpoints (also Conditional Breakpoints and Console)
     o Watch expressions
     o NET panel for XHR requests
     o Call stack
Browser-specific Tools

From "worst" to "best" (IMHO)....

• IE6/7: MS Script Debugger/MS Script Editor/MS Visual
  Studio (also IE Dev Toolbar)
• IE8: Developer Tools (can run in IE7 mode)
• Safari: Web Inspector
• Chrome: Developer Tools + JS Console
• Firefox: Firebug
Internet Explorer 6 & 7

• Need to enable JS errors in browser settings ("Display a
  notification for every script error")
• MS Script Debugger/MS Script Editor/MS Visual Studio
   o Separate downloads
   o Separate app, runs alongside the browser
   o Complicated to set-up
   o Clunky & difficult to use


• IE Dev Toolbar (But no JS debugger!)
• No easy way to disable JS on the fly
Internet Explorer 6 & 7
Internet Explorer 6 & 7
IE8: Developer Tools

•   Built into browser
•   Enable via Tools » Developer Tools
•   DOM inspector & JS debugger/profiler
•   IE7 mode
•   Can disable JS on the fly
IE8: Developer Tools
Safari: Web Inspector

•   Built into browser
•   Enable via Preferences » Advanced » Show Develop Menu
•   DOM Inspector + JS Debugger + Network + Console
•   Can disable JS under Develop menu
Safari: Web Inspector
Chrome: Developer Tools

•   Built into browser
•   Enable via View » Developer » Developer Tools
•   DOM Inspector + Network + JS Debugger + Console
•   Latest versions can pretty-print code
•   Can't disable JS on the fly
Chrome: Developer Tools
Firefox: Firebug

•   Add-on browser extension (http://getfirebug.com)
•   Enable via Tools » Firebug » Open Firebug
•   Console + Profiler + Debugger + Network
•   Can disable JS on the fly
•   Currently the "best" option (Chrome Dev Tools are a close
    second)
Firefox: Firebug
Firefox: Firebug
General Tools

• alert("something"); creates a popup dialog in most
  browsers
• console.log("something"); writes to browser's JS
  console if available
• JSLint (http://www.jslint.com/)
• YUI Logger (http://developer.yahoo.com/yui/logger/)
• Firebug Lite (http://getfirebug.com/firebuglite)
Common Gotchas
• Suppressed errors
    window.onerror = function() {};
    eval(/* some code here */);

• Compressed/Minified code
    function a(){var d,b=1,c=2;d=b+c;}

• Trailing commas in IE
     var config = {
            foo: "a thing",
            bar: "another thing",
            baz: "yet another thing",
     }

• Conflicting AJAX requests -- use Network panel to inspect
Using a Debugger

–   Where is the broken code? (Browser errors or console)
–   Set breakpoint(s)
–   Re-run script (reload or click)
–   Step through code (in/over/out) & inspect variables
–   Test using console
–   Fix code & repeat
Firefox: Firebug
Now You Try It!

1. Add Firebug to Firefox

– Browse to http://scream-
  ld.linkedin.biz/~jgourgou/jsdebug/excercises/

– Find the bugs in the examples!
Further Reading

• http://www.alistapart.com/articles/advanced-debugging-with-jav
  /
• http://blogs.msdn.com/b/ie/archive/2004/10/26/247912.aspx
• http://www.jonathanboutelle.com/how-to-debug-javascript-in-in
  explorer
• https://developer.mozilla.org/en/Debugging_JavaScript
• http://www.webmonkey.com/2010/02/javascript_debugging_for

More Related Content

Similar to Javascript Debugging

jQueryTO: State of jQuery March 2013
jQueryTO: State of jQuery March 2013jQueryTO: State of jQuery March 2013
jQueryTO: State of jQuery March 2013
dmethvin
 
Web development-work space
Web development-work spaceWeb development-work space
Web development-work space
chawlan
 
Web dev tools review
Web dev tools reviewWeb dev tools review
Web dev tools review
Changhyun Lee
 
JavaScript debugging diagnostic web tools and firefox
JavaScript debugging diagnostic web tools and firefoxJavaScript debugging diagnostic web tools and firefox
JavaScript debugging diagnostic web tools and firefox
Gennady Feldman
 
[ENG] Hacker halted 2012 - Zombie browsers, spiced with rootkit extensions
[ENG] Hacker halted 2012 - Zombie browsers, spiced with rootkit extensions[ENG] Hacker halted 2012 - Zombie browsers, spiced with rootkit extensions
[ENG] Hacker halted 2012 - Zombie browsers, spiced with rootkit extensions
Zoltan Balazs
 
Java scriptwidgetdevelopmentjstanbul2012
Java scriptwidgetdevelopmentjstanbul2012Java scriptwidgetdevelopmentjstanbul2012
Java scriptwidgetdevelopmentjstanbul2012
Volkan Özçelik
 
State of jQuery - AspDotNetStorefront Conference
State of jQuery - AspDotNetStorefront ConferenceState of jQuery - AspDotNetStorefront Conference
State of jQuery - AspDotNetStorefront Conference
dmethvin
 

Similar to Javascript Debugging (20)

Inspect The Uninspected
Inspect The UninspectedInspect The Uninspected
Inspect The Uninspected
 
Cape Cod Web Technology Meetup - 3
Cape Cod Web Technology Meetup - 3Cape Cod Web Technology Meetup - 3
Cape Cod Web Technology Meetup - 3
 
orcreatehappyusers
orcreatehappyusersorcreatehappyusers
orcreatehappyusers
 
orcreatehappyusers
orcreatehappyusersorcreatehappyusers
orcreatehappyusers
 
jQueryTO: State of jQuery March 2013
jQueryTO: State of jQuery March 2013jQueryTO: State of jQuery March 2013
jQueryTO: State of jQuery March 2013
 
Web development-work space
Web development-work spaceWeb development-work space
Web development-work space
 
Web dev tools review
Web dev tools reviewWeb dev tools review
Web dev tools review
 
JavaScript debugging diagnostic web tools and firefox
JavaScript debugging diagnostic web tools and firefoxJavaScript debugging diagnostic web tools and firefox
JavaScript debugging diagnostic web tools and firefox
 
Debugging webOS applications
Debugging webOS applicationsDebugging webOS applications
Debugging webOS applications
 
[ENG] Hacker halted 2012 - Zombie browsers, spiced with rootkit extensions
[ENG] Hacker halted 2012 - Zombie browsers, spiced with rootkit extensions[ENG] Hacker halted 2012 - Zombie browsers, spiced with rootkit extensions
[ENG] Hacker halted 2012 - Zombie browsers, spiced with rootkit extensions
 
Marco Liberati - Write once, debug everywhere
Marco Liberati - Write once, debug everywhereMarco Liberati - Write once, debug everywhere
Marco Liberati - Write once, debug everywhere
 
External JavaScript Widget Development Best Practices
External JavaScript Widget Development Best PracticesExternal JavaScript Widget Development Best Practices
External JavaScript Widget Development Best Practices
 
Java scriptwidgetdevelopmentjstanbul2012
Java scriptwidgetdevelopmentjstanbul2012Java scriptwidgetdevelopmentjstanbul2012
Java scriptwidgetdevelopmentjstanbul2012
 
External JavaScript Widget Development Best Practices (updated) (v.1.1)
External JavaScript Widget Development Best Practices (updated) (v.1.1) External JavaScript Widget Development Best Practices (updated) (v.1.1)
External JavaScript Widget Development Best Practices (updated) (v.1.1)
 
State of jQuery - AspDotNetStorefront Conference
State of jQuery - AspDotNetStorefront ConferenceState of jQuery - AspDotNetStorefront Conference
State of jQuery - AspDotNetStorefront Conference
 
Browser Developer Tools
Browser Developer ToolsBrowser Developer Tools
Browser Developer Tools
 
How browser work
How browser workHow browser work
How browser work
 
.Net Debugging Techniques
.Net Debugging Techniques.Net Debugging Techniques
.Net Debugging Techniques
 
.NET Debugging Tips and Techniques
.NET Debugging Tips and Techniques.NET Debugging Tips and Techniques
.NET Debugging Tips and Techniques
 
Phonegap Development & Debugging
Phonegap Development & DebuggingPhonegap Development & Debugging
Phonegap Development & Debugging
 

Recently uploaded

Recently uploaded (20)

Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 

Javascript Debugging

  • 2. Agenda • Browser-Specific Tools o IE 6/7: MS Script Debugger, MS Script Editor, MS Visual Studio (also IE Dev Toolbar) o IE 8: Developer Tools o Safari: Web Inspector o Chrome: Dev Tools (JS Console, DOM Inspector) o FireFox: Firebug • General Tools o YUI Logger o Alerts, prompts, and console.log() o JSLint • Common Pitfalls o Suppressed errors o Trailing commas in IE o Conflicting XHR requests • Using a Debugger o Step In/Over/Out o Breakpoints (also Conditional Breakpoints and Console) o Watch expressions o NET panel for XHR requests o Call stack
  • 3. Browser-specific Tools From "worst" to "best" (IMHO).... • IE6/7: MS Script Debugger/MS Script Editor/MS Visual Studio (also IE Dev Toolbar) • IE8: Developer Tools (can run in IE7 mode) • Safari: Web Inspector • Chrome: Developer Tools + JS Console • Firefox: Firebug
  • 4. Internet Explorer 6 & 7 • Need to enable JS errors in browser settings ("Display a notification for every script error") • MS Script Debugger/MS Script Editor/MS Visual Studio o Separate downloads o Separate app, runs alongside the browser o Complicated to set-up o Clunky & difficult to use • IE Dev Toolbar (But no JS debugger!) • No easy way to disable JS on the fly
  • 7. IE8: Developer Tools • Built into browser • Enable via Tools » Developer Tools • DOM inspector & JS debugger/profiler • IE7 mode • Can disable JS on the fly
  • 9. Safari: Web Inspector • Built into browser • Enable via Preferences » Advanced » Show Develop Menu • DOM Inspector + JS Debugger + Network + Console • Can disable JS under Develop menu
  • 11. Chrome: Developer Tools • Built into browser • Enable via View » Developer » Developer Tools • DOM Inspector + Network + JS Debugger + Console • Latest versions can pretty-print code • Can't disable JS on the fly
  • 13. Firefox: Firebug • Add-on browser extension (http://getfirebug.com) • Enable via Tools » Firebug » Open Firebug • Console + Profiler + Debugger + Network • Can disable JS on the fly • Currently the "best" option (Chrome Dev Tools are a close second)
  • 16. General Tools • alert("something"); creates a popup dialog in most browsers • console.log("something"); writes to browser's JS console if available • JSLint (http://www.jslint.com/) • YUI Logger (http://developer.yahoo.com/yui/logger/) • Firebug Lite (http://getfirebug.com/firebuglite)
  • 17. Common Gotchas • Suppressed errors window.onerror = function() {}; eval(/* some code here */); • Compressed/Minified code function a(){var d,b=1,c=2;d=b+c;} • Trailing commas in IE var config = { foo: "a thing", bar: "another thing", baz: "yet another thing", } • Conflicting AJAX requests -- use Network panel to inspect
  • 18. Using a Debugger – Where is the broken code? (Browser errors or console) – Set breakpoint(s) – Re-run script (reload or click) – Step through code (in/over/out) & inspect variables – Test using console – Fix code & repeat
  • 20. Now You Try It! 1. Add Firebug to Firefox – Browse to http://scream- ld.linkedin.biz/~jgourgou/jsdebug/excercises/ – Find the bugs in the examples!
  • 21. Further Reading • http://www.alistapart.com/articles/advanced-debugging-with-jav / • http://blogs.msdn.com/b/ie/archive/2004/10/26/247912.aspx • http://www.jonathanboutelle.com/how-to-debug-javascript-in-in explorer • https://developer.mozilla.org/en/Debugging_JavaScript • http://www.webmonkey.com/2010/02/javascript_debugging_for