Mugshot: Recording and Replaying JavaScript Applica9ons. James Mickens

Similar documents
JavaScript and XHTML. Prof. D. Krupesha, PESIT, Bangalore

Software Architecture and Engineering: Part II

CITS3403 Agile Web Development Semester 1, 2018

JavaScript and Events

AJAX ASYNCHRONOUS JAVASCRIPT AND XML. Laura Farinetti - DAUIN

Debugging AJAX in Production

CSI 3140 WWW Structures, Techniques and Standards. Browsers and the DOM

EventRacer: Finding Concurrency Errors in Event-Driven Applications. Pavol Bielik

JavaScript: Events, DOM and Attaching Handlers

JavaScript Programming

Interactor Tree. Edith Law & Mike Terry

DYNAMICALLY CACHING VIDEO CONTENT BASED ON USER LIKELIHOOD OF INTERACTING WITH CONTENT ELEMENT

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)

THE NEW ERA OF WEB DEVELOPMENT. qooxdoo. Andreas Ecker, Derrell Lipman

729G26 Interaction Programming. Lecture 4

End User Monitoring. AppDynamics Pro Documentation. Version 4.2. Page 1

Client-side Debugging. Gary Bettencourt

Outline. Lecture 4: Document Object Model (DOM) What is DOM Traversal and Modification Events and Event Handling

Javascript. Many examples from Kyle Simpson: Scope and Closures

Processes. CS 416: Operating Systems Design, Spring 2011 Department of Computer Science Rutgers University

Part of this connection identifies how the response can / should be provided to the client code via the use of a callback routine.

Catching Events. Bok, Jong Soon

Test Automation to the Limit

Project 3 Web Security Part 1. Outline

2/6/2012. Rich Internet Applications. What is Ajax? Defining AJAX. Asynchronous JavaScript and XML Term coined in 2005 by Jesse James Garrett

Using Replicated Execu2on for a More Secure and Reliable Browser. Hui Xue, Nathan Dautenhahn, Sam King University of Illinois at Urbana Champaign

End User Monitoring. AppDynamics Pro Documentation. Version Page 1

Sample CS 142 Midterm Examination

Fall UI Design and Implementation 1

Web applica*on security for dynamic

Client vs Server Scripting

EECS1012. Net-centric Introduction to Computing. Lecture JavaScript Events

End User Monitoring. AppDynamics Pro Documentation. Version Page 1

Photo from DOM


Designing RIA Accessibility: A Yahoo UI (YUI) Menu Case Study

DoDOM: Leveraging DOM Invariants for Web 2.0 Applica<on Robustness Tes<ng

NODE.JS SERVER SIDE JAVASCRIPT. Introduc)on Node.js

PHP / MYSQL DURATION: 2 MONTHS

Interactive Programming

JavaScript. The Bad Parts. Patrick Behr

Session 6. JavaScript Part 1. Reading

JavaScript Handling Events Page 1

JavaScript By: A. Mousavi & P. Broomhead SERG, School of Engineering Design, Brunel University, UK

Fast Mobile UIs. You re an Edge Case. Thursday, 8 March, 12

Virtual Memory: Concepts

5. Strict mode use strict ; 6. Statement without semicolon, with semicolon 7. Keywords 8. Variables var keyword and global scope variable 9.

UI Course HTML: (Html, CSS, JavaScript, JQuery, Bootstrap, AngularJS) Introduction. The World Wide Web (WWW) and history of HTML

Index. Ray Nicholus 2016 R. Nicholus, Beyond jquery, DOI /

CS 498RK FALL RESTFUL APIs

LECTURE-3. Exceptions JS Events. CS3101: Programming Languages: Javascript Ramana Isukapalli

JQuery WHY DIDN T WE LEARN THIS EARLIER??!

Jinx Malware 2.0 We know it s big, we measured it! Itzik Kotler Yoni Rom

Introduction to JavaScript p. 1 JavaScript Myths p. 2 Versions of JavaScript p. 2 Client-Side JavaScript p. 3 JavaScript in Other Contexts p.

AJAX Programming Chris Seddon

Command-driven, event-driven, and web-based software


Why Discuss JavaScript? CS312: Programming Languages. Lecture 21: JavaScript. JavaScript Target. What s a Scripting Language?

ThingLink User Guide. Andy Chen Eric Ouyang Giovanni Tenorio Ashton Yon

Standard 1 The student will author web pages using the HyperText Markup Language (HTML)

Pivot: Fast, Synchronous Mashup Isolation Using Generator Chains

CS312: Programming Languages. Lecture 21: JavaScript

Koenig Solutions Pvt. Ltd. Selenium with C#

SEDA An architecture for Well Condi6oned, scalable Internet Services

Dynamic Web Development

Implementing a Numerical Data Access Service

ASP.NET MVC Training

Socket To Me. Instead of the usual request/ response. Features Perl: WebSockets

of numbers, converting into strings, of objects creating, sorting, scrolling images using, sorting, elements of object

Hell is other browsers - Sartre. The touch events. Peter-Paul Koch (ppk) DIBI, 28 April 2010

Elementary Computing CSC 100. M. Cheng, Computer Science

Fighting Layout Bugs. Techniques to automatically verify the work of HTML and CSS programmers QCon London 2010

Elementary Computing CSC 100. M. Cheng, Computer Science

AWS Lambda + nodejs Hands-On Training

AJAX Programming Overview. Introduction. Overview

Developing ASP.Net MVC 4 Web Application

AJAX: Rich Internet Applications

Flexible and LEAN Ads

20486: Developing ASP.NET MVC 4 Web Applications

Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England and Associated Companies throughout the world

Unusual Web Bugs. A Web App Hacker s Bag O Tricks. Alex kuza55 K.

CS142 Winter 2017 Midterm Grading Solutions and Rubric

COURSE 20486B: DEVELOPING ASP.NET MVC 4 WEB APPLICATIONS

Single and mul,threaded processes

Ajax or AJAX? The acronym AJAX has changed to the term Ajax, which does not represent specific technologies

Some Facts Web 2.0/Ajax Security

AJAX: Asynchronous Event Handling Sunnie Chung

CSE 154 LECTURE 26: JAVASCRIPT FRAMEWORKS


Lesson: Web Programming(6) Omid Jafarinezhad Sharif University of Technology

jquery Cookbook jquery Community Experts O'REILLY8 Tokyo Taipei Sebastopol Beijing Cambridge Farnham Koln

AJAX: The Basics CISC 282 March 25, 2014

How manual testers can break into Test Automation without programming skills

UPCRC. Illiac. Gigascale System Research Center. Petascale computing. Cloud Computing Testbed (CCT) 2

iframe programming with jquery jquery Summit 2011

Developing ASP.NET MVC 4 Web Applications

Web Programming Step by Step

The Multi-Principal OS Construction of the Gazelle Web Browser. Helen J. Wang, Chris Grier, Alex Moshchuk, Sam King, Piali Choudhury, Herman Venter

Programing for Digital Media EE1707. Lecture 4 JavaScript By: A. Mousavi & P. Broomhead SERG, School of Engineering Design, Brunel University, UK


Transcription:

Mugshot: Recording and Replaying JavaScript Applica9ons James Mickens Jeremy Elson Jon Howell

I ALREADY LEARNED THIS TO YOU. XOXO, JAMES Modern web sites: eventdriven func9onality via JavaScript mapitem.onclick = func9on(){ mapcontrol.zoomlevel++; mapcontrol.fetchtiles(); mapcontrol.displaytiles(); };

Hard errors Unexpected excep9on Missing resource SoS errors Layout glitch Broken event handler Poor performance

When Things Go Wrong Common post mortems Core dump Stack trace Error log In event driven systems interleavings are key! Shouldn t rely on user to report nondeterminis9c events

Our Solu9on: Mugshot Logs nondeterminis9c JavaScript events Ex: Mouse clicks, date requests, random number genera9on On panic, upload event log to developer machine Developers replays the buggy program run Single step or (near) real 9me playback Developer can leverage rich localhost debuggers...... using buggy applica9ons runs from the wild!

Why Mugshot Is Awesome Easy to deploy to end users Logging/replay code is just a JavaScript library Ship Mugshot infrastructure with the applica9on: <script src= mugshot.js ></script> Don t need special kernel/vm/browser! Logging is lightweight: run in common case Log size: Worst case 16 Kbps CPU: Worst case 7% reduc9on in frame rate Solves an important, prac9cal problem Increasingly complex apps migra9ng to the web Remote bug repro is very important!

Outline Logging Replay Evalua9on Conclusion

Parent frame Parent Bujon Child frame 1 Child frame 2 Child 1 Bujon Child 2 Bujon

<html> <head> <script src= logger.js ></script> </head> <body> <bujon type= bujon onclick= alert(date()) /> <iframe> </iframe> <iframe> </iframe> </body> </html> Event Log <script src= logger.js ></script> <bujon type= bujon onclick= alert(date()) > <script src= logger.js ></script> <bujon type= bujon onclick= alert(date()) >

Official W3C Event Model <iframe> <bujon type=`bujon` onclick=`alert(date())`/> </iframe> 1 3 1 2 Child frame 2 Child 2 Bujon 2 3 Phase 1: Capturing Phase 2: Target Phase 3: Bubbling

Event Log Parent frame Parent Bujon Child frame 1 Child frame 2 Child 1 Bujon bujon.onclick = func9on(){ Child 2 Bujon alert(date()); } Nondeterminism to log 1) Click (mouse bujon, target) 2) Return value of Date()

Logging Events on Firefox Logging Date() is straighporward...... just enclose real Date() in logging wrapper Logging mouse click is straighporward 1) Capturing phase (iframe) 2) Target phase (bujon) <iframe> onclick= mugshotcapturinglogger() > <script src= logger.js ></script> <bujon type= bujon onclick= alert( Date() ) > </iframe> Event log Event: Click Time: 1000 Value: Child 2 bujon LeS click X=312, Y=209 Event: Date Time: 2000

Seems simple, right?

DOM 0 versus DOM 2 Handlers var f = document.getelementbyid( child2frame ); f.onclick = func9on(){alert( DOM 0 handler )}; f.addeventlistener( click, func9on(){alert( DOM 1 handler ), true); For any DOM node/event name pair: At most one DOM 0 handler Arbitrary number of DOM 2 handlers

Life Is So Difficult Firefox calls DOM 0 handler before DOM 2 handlers DOM 2 handlers called in order of registra9on Mugshot must ensure that its handler runs before any app defined ones App handler can cancel event...... but we s9ll need to log it!

Life Is So Difficult We d like to run before the app and... Define DOM 2 logging handler for onclick Use JavaScript sejer shim to interpose on assignment to iframe.onclick This would let us: Use DOM 2 logging func if no app defined DOM 0 handler Wrap app defined DOM 0 handler in logging code The problem: Firefox sejers are par9ally broken Browser will not invoke DOM 0 handler for node with a shimmed DOM 0 event property

Life Is So Difficult Fortunately, sejers for DOM 0 handlers don t keep browser from firing DOM 2 handlers So, sejer code registers DOM 0 app handler as DOM 2 handler too Sejer removes DOM 2 handler if backing DOM 0 handler is reset

Recap: Logging Events on Firefox <iframe onclick= mugshotcapturinglogger() > <script src= logger.js ></script> <bujon type= bujon onclick= alert( Date() ) > </iframe> Strategery

Logging Events on IE Logging Date() is straighporward...... just enclose real Date() in logging wrapper Logging GUI events is tricky in IE! There is no capture phase! 2) Bubbling phase (iframe) <iframe> onclick= mugshotbubblinglogger() > <script src= logger.js ></script> <bujon type= bujon onclick= alert(date()) > 1) Target phase </iframe> (bujon) Event log Event: Date Time: 1000 Event: Click Time: 2000 Value: Child 2 bujon LeS click X=312, Y=209

Logging Events on IE Logging Date() is straighporward...... just enclose real Date() in logging wrapper Logging GUI events is tricky in IE! There is no capture phase! 1) Target phase (bujon) 2) Bubbling phase Doesn t log the already logged event (iframe) <iframe onclick= mugshotbubblinglogger() > <script src= logger.js ></script> <bujon type= bujon onclick= alert(date()) > </iframe> Event log Event: Date Time: 1000 Is there an unlogged GUI event? Event: Click Time: 1000 Value: Child 2 bujon LeS click X=312, Y=209

Sources of Nondeterminism DOM Events Asynchronous callbacks Mouse Key Loads Form Body Set 9mer AJAX state change Nondeterminis9c func9ons Get current 9me Get random number Text selec9on Category Event Type Example IE: document.selec9on FF: window.getselec9on() click, mouseover keydown, keyup load focus, blur, select scroll, resize settimeout(f, 100) req.onchange = f (new Date()).getTime() Math.random() Highlight text w/mouse Highlight text w/mouse

How Do We Log settimeout(f, 50)? Interpose on settimeout() var oldsettimeout = settimeout; settimeout = func9on(f, waitms){ f.callbackid = Mugshot.nextCallbackId++; var wrappedf = func9on(){ logcallbackexecu9on(f.callbackid); f(); }; oldsettimeout(wrappedf, waitms); }; Easy, right?

Browser garbage collects this reference!?! var oldsettimeout = settimeout; settimeout = func9on(f, waitms){ f.callbackid = Mugshot.nextCallbackId++; var wrappedf = func9on(){ logcallbackexecu9on(f.callbackid); f(); }; oldsettimeout(wrappedf, waitms); }; Call to oldsettimeout() will fail (undefined func9on)!

I Hate Myself And I Want To Die Solu9on: Create an invisible iframe! Save its reference to settimeout()...... and call it inside the wrapped callback Have to do this nonsense at replay 9me too Mugshot uses a variety of addi9onal hacks See the paper for details

Logging the Value of Loads Web server Replay proxy 1 2 User browser 3 2 4 Replay Cache 1) Original content served 2) Replay proxy caches data before sending to client, instruments HTML with log.js 3) User interacts with page, log.js records local events 4) On failure, log.js uploads event trace

Outline Logging Replay Evalua9on Conclusion

Using the Replay Proxy Replay proxy 1 Developer browser 2 3 4 4 Replay Cache 1) Proxy changes log.js replay.js, serves cached HTML page 2) replay.js prevents browser from autonomously genera9ng events 3) replay.js fetches event log 4) replay.js replays events, fetching external content from replay proxy

On The Developer Machine: replay.js 1) Put transparent <iframe> on top of page 2) Interpose on Date(), Math.random(), settimeout() 3) Fetch log and display VCR control 4) To replay, step through log... Dispatch fake GUI events using fireevent()/dispatchevent() Execute 9mer func9ons as they appear in log As app code executes, pull return values of Date() and Math.random() from the log When load arrives, signal replay proxy to release the data

Outline Logging Replay Evalua9on Conclusion

Log Growth Firefox Log Growth (Kbps) 100 75 50 25 0 Verbose Compact Tetris Pacman Spacius BASIC Painter NicEdit Shell

Timer Callback Rates Spacius: CBs per second 100 80 60 40 20 Baseline Logging Replay 0 Firefox IE

Reproducing Bugs

Conclusion

Conclusion Mugshot: trace+replay for JavaScript apps Easy to deploy: run a script inside unmodified browser Lightweight: 7% CPU overhead, 16 Kbps log growth Design is straighporward...... but implementa9on is not! Take my learnings, make them your own