SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Ähnlich wie 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Kürzlich hochgeladen (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

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