   constructor: ->
     @progress = 0
 
+    _onreadystatechange = document.onreadystatechange
     document.onreadystatechange = =>
       if @states[document.readyState]?
         @progress = @states[document.readyState]
+
+      _onreadystatechange?(arguments...)
 
 class EventLagMonitor
   constructor: ->

    bar.update uniScaler.tick(frameTime, avg)

    start = now()
    if bar.done() or done
      bar.update 100

      setTimeout ->

  constructor: (request) ->
    @progress = 0

    if request.onprogress isnt undefined
      # It will be null, not undefined, on browsers which don't support it
      
      size = null
      _onprogress = request.onprogress
      request.onprogress = =>
        try
          headers = request.getAllResponseHeaders()

          for name, val of headers
            if name.toLowerCase() is 'content-length'
              size = +val
              break

        catch e

        if size?
          # This is not perfect, as size is in bytes, length is in chars
          try
            @progress = request.responseText.length / size
          catch e
        else
          # If it's chunked encoding, we have no way of knowing the total length of the
          # response, all we can do is increment the progress with backoff such that we
          # never hit 100% until it's done.
          @progress = @progress + (100 - @progress) / 2

      _onprogress?(arguments...)

    _onreadystatechange = request.onreadystatechange
    request.onreadystatechange = =>
      if request.readyState in [0, 4]
        @progress = 100
      else if not request.onprogress? and request.readyState is 3
        @progress = 50

      _onreadystatechange?(arguments...)

class ElementMonitor
  constructor: (selectors...) ->
