JavaScript Errors in the Wild: An Empirical Study Frolin S. Ocariza, - - PowerPoint PPT Presentation

javascript errors in the wild an empirical study
SMART_READER_LITE
LIVE PREVIEW

JavaScript Errors in the Wild: An Empirical Study Frolin S. Ocariza, - - PowerPoint PPT Presentation

JavaScript Errors in the Wild: An Empirical Study Frolin S. Ocariza, Jr. 1 Karthik Pattabiraman 1 Benjamin Zorn 2 1 University of British Columbia (UBC), 2 Microsoft Research (MSR) Web 2.0 Application: Amazon.com Third Menu Amazons party


slide-1
SLIDE 1

JavaScript Errors in the Wild: An Empirical Study

Frolin S. Ocariza, Jr.1 Karthik Pattabiraman1 Benjamin Zorn2

1 University of British Columbia (UBC), 2Microsoft Research (MSR)

slide-2
SLIDE 2

Web 2.0 Application: Amazon.com

2

Amazon’s

  • wn ad

Menu bar Shopping cart Third party gadget ad Web 2.0 applications allow rich UI functionality within a single web page

slide-3
SLIDE 3

Web 2.0 Application: JavaScript

3

Significant amount of JavaScript code executing in the browser

slide-4
SLIDE 4

Web 2.0 Application: Amazon.com

4

Web Apps experience errors, yet they continue to execute !

slide-5
SLIDE 5

Web 2.0 Applications: Problems

5

Loose semantics Multiple Clients DOM an error occurred when processing this directive

! Snapshot of

iFeng.com: Leading media website in China

slide-6
SLIDE 6

Studies of JavaScript Web Applications

6

Performance and parallelism: JSMeter [Ratanaworabhan-2010], [Richards-2009], [Fortuna-2011] Reliability

?

Security and Privacy: [Yue-2009], Gatekeeper [Guarnieri-2009], [Jang-2010] performance security reliability Goal: Study the reliability of web applications in the “wild”

slide-7
SLIDE 7

Contributions

7

! Devised methodology to collect and categorize JS error

messages from web applications

! Characterized JS error messages that appeared in 50 top

websites

! Analysis of the implications of results

! Find possible ways to write more reliable JS code ! Improve the quality of JS testing ! Highlight JS characteristics that should be captured by static

analysis tools

slide-8
SLIDE 8

JavaScript Error Messages

8

! Any exception thrown by JS code is logged to JS console

Multiple exceptions

slide-9
SLIDE 9

Error Messages: Pros and Cons

9

! Pros

! No false positives unlike static analysis ! Challenging to analyze JavaScript statically ! Capture interactions with the DOM

! Cons

! Error message may be benign

! Still an indication of potential problem

! May be incomplete

! Publicly available JS bug reports very limited

slide-10
SLIDE 10

Steps to Collect Error Messages

10

! Chose 50 web applications from the Alexa top 100 ! Created test suites for normal interactions in Selenium ! Capture JavaScript Errors printed to Firebug console

slide-11
SLIDE 11

Research Questions

11

Do errors occur in web apps and if so, what categories do they fall in ? How do errors vary by speed of testing ? Are they all deterministic ? How do errors correlate with static and dynamic characteristics of the app?

slide-12
SLIDE 12

Firebug Error Messages

12

  • 1. Description of error message
  • 2. Line of code corresponding to error
  • 3. File name and line number

T wo errors are different if any attribute is different

slide-13
SLIDE 13

Errors and their classification: Results

13

! Average of 4 distinct error messages for each app

! Standard dev: 3 ! Max: 16 (Cnet) ! Min: 0 (Google)

2 4 6 8 10 12 14 16 18

T

  • tal Distinct Errors

Web Application # of Errors

slide-14
SLIDE 14

Errors and their classification: Results (2)

14

! 94 % of errors fall into four predominant categories

54% 9% 27% 4% 6%

Distribution of Error Messages

# of Permission Denied Errors # of Null Exception Errors # of Undefined Symbol Errors # of Syntax Errors # of Miscellaneous Errors

slide-15
SLIDE 15

Permission Denied Example

15

advertisement

  • Error Message: Permission denied for http://view.atdmt.com to call method

Location.toString on http://www.imdb.com

  • Explanation: Triggered by appearance of advertisement. Leads to SOP violation.

Bottom Line: JS errors may appear as a result of code written by others Taken from imdb.com 54% 9% 27% 4% 6%

slide-16
SLIDE 16

Undefined Symbol Example

Taken from cnn.com

  • Error Message: cnn_onMemFBInit() is undefined

if (CNN_ISMemInit && CNN_IsFBInit) cnn_onMemFBInit();

  • Explanation: Both CNN_IsMemInit and CNN_IsFBInit set to true
  • Bottom Line: JS code is difficult to maintain

// this probably isn’t needed anymore

16

54% 9% 27% 4% 6%

slide-17
SLIDE 17

Null Exception Example

Taken from amazon.com

  • Error Message: document.getElementById(“inappDiv”) is null

document.getElementById(“inappDiv”).style.display = ‘none’;

  • Explanation: inappDiv was only defined for users who are logged in
  • Bottom Line: JS code may depend on the DOM

Causes error

  • n click

17

54% 9% 27% 4% 6%

slide-18
SLIDE 18

Syntax Error Example

Taken from about.com

  • Error Message: unterminated string literal

zGPU = ‘http://movies.about.com/od/onlinemovies Movies_Available_on_the_Internet.html’”

  • Bottom Line: JS code is sometimes not well-tested

54% 9% 27% 4% 6%

slide-19
SLIDE 19

Research Questions

19

Do errors occur in web apps and if so, what categories do they fall in ? How do errors vary by speed of testing ? Are they all deterministic ? How do errors correlate with static and dynamic characteristics of the app?

slide-20
SLIDE 20

Effect of Testing Speed: Method

20

! Varied testing speed for replaying events ! Performed three executions in each testing speed

0 ms 1000 ms Fast Medium Slow 500 ms

slide-21
SLIDE 21

Effect of Testing Speed: Results

21

Error Message (shortened) F 1 F 2 F 3 M 1 M 2 M 3 S 1 S 2 S 3 Permission Denied for view.atdmt.com to call <fname> on marquee.blogs.cnn.com 4 4 4 1 3 3 2 2 3 targetWindow.cnnad showAd is not a function 2 5 window.parent.CSIManager is un- defined 1 1

slide-22
SLIDE 22

Non-Deterministic Error: Example

! Tumblr page

change_promo(promo) ! expects promo to be within range 1-4 setTimeout(change_promo, 5000) ! no parameter specified, so random value for promo No exception if promo within range Exception if promo out of range

slide-23
SLIDE 23

Effect of Testing Speed: Non-Determinism

23

! More than 70% of distinct errors are non-deterministic Total non-deterministic errors

slide-24
SLIDE 24

Research Questions

24

Do errors occur in web apps and if so, what categories do they fall in ? How do errors vary by speed of testing ? Are they all deterministic ? How do errors correlate with static and dynamic characteristics of the app?

slide-25
SLIDE 25

Static/Dynamic Correlations: Summary

Static Characteristics Dynamic Characteristics

25

! Number of called functions ! Number of eval calls ! Properties deleted ! Object inheritance overridings

  • Alexa Rank
  • Bytes of JavaScript code
  • Number of domains
  • Domains containing JS

From Richards et al. [PLDI – 2010] Measured using Phoenix & Firebug plugins

slide-26
SLIDE 26

Dynamic Correlations: Eval Calls

! Low correlation

! Compare: eval calls

! correlate well with security

slide-27
SLIDE 27

Static Correlations: JS Code Size

! Low correlation

! JS reliability not tied very closely to code size

slide-28
SLIDE 28

Research Questions: Answers

28

Do errors occur in web apps and what categories do they fall in ? How do errors vary by speed of testing ? Are they all deterministic ? How do errors correlate with static and dynamic characteristics of the app? Average of four errors in each app. Errors fall into four well-defined categories Errors vary by speed of

  • testing. Majority of errors

are non-deterministic Correlated with no of domains, # of domains with JS, Alexa rank, but not with eval calls and code size

slide-29
SLIDE 29

Implications of Results

29

! Programmers

! Need to make code robust against other code/scripts ! Make sure interactions with DOM are checked

! T

esters

! Perform integration testing to see effects of ads ! Need to test at multiple testing speeds, multiple times

! Static analysis tool developers

! Target most common classes of errors ! Need to model the DOM in the analysis

slide-30
SLIDE 30

Conclusion and Future Work

! JavaScript code in production web apps ! buggy! ! Study exposes JS reliability problems and analyzes errors

! Data publicly available

! http://ece.ubc.ca/~frolino/project/jser

! Future work

! Better understanding of causes (root causes and correlations) ! Currently: Fault localization

slide-31
SLIDE 31

Backup Slides

slide-32
SLIDE 32

0.1 1 10 100 1000 10000 100000

Eval Calls (from Richards et al. [PLDI-2010])

JavaScript: “Good” or “Evil” ?

32

Versus

Real web applications do not stick to the “good” parts

E v a l s