Class: ChromeDebugger::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/chrome_debugger/document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Document

Returns a new instance of Document.


12
13
14
15
16
# File 'lib/chrome_debugger/document.rb', line 12

def initialize(url)
  @url       = url
  @timestamp = 0
  @events    = []
end

Instance Attribute Details

#eventsObject (readonly)

Returns the value of attribute events


10
11
12
# File 'lib/chrome_debugger/document.rb', line 10

def events
  @events
end

#urlObject (readonly)

Returns the value of attribute url


10
11
12
# File 'lib/chrome_debugger/document.rb', line 10

def url
  @url
end

Instance Method Details

#bytes(resource_type) ⇒ Object

The number of bytes downloaded for a particular resource type. If the resource was gzipped during transfer then the uncompressed size is reported.

The HTTP headers for the response are NOT included in the byte count.

Possible resource types: 'Document','Script', 'Image', 'Stylesheet', 'Other'.


79
80
81
82
83
84
85
86
87
# File 'lib/chrome_debugger/document.rb', line 79

def bytes(resource_type)
  @events.select {|e|
    e.is_a?(ResponseReceived) && e.resource_type == resource_type
  }.map { |e|
    e.request_id
  }.map { |request_id|
    data_received_for_request(request_id)
  }.flatten.inject(0) { |bytes_sum, n| bytes_sum + n.data_length }
end

#dom_content_eventObject

The number of seconds after start_time the the DomReady event fired


43
44
45
46
47
48
49
50
# File 'lib/chrome_debugger/document.rb', line 43

def dom_content_event
  @dom_content_event ||= begin
                           ts = @events.select { |event|
                             event.is_a?(DomContentEventFired)
                           }.slice(0,1).map(&:timestamp).first
                           ts ? (ts - start_time).round(3) : nil
                         end
end

#encoded_bytes(resource_type) ⇒ Object

The number of bytes downloaded for a particular resource type. If the resource was gzipped during transfer then the gzipped size is reported.

The HTTP headers for the response are included in the byte count.

Possible resource types: 'Document','Script', 'Image', 'Stylesheet', 'Other'.


60
61
62
63
64
65
66
67
68
# File 'lib/chrome_debugger/document.rb', line 60

def encoded_bytes(resource_type)
  @events.select {|e|
    e.is_a?(ResponseReceived) && e.resource_type == resource_type
  }.map { |e|
    e.request_id
  }.map { |request_id|
    data_received_for_request(request_id)
  }.flatten.inject(0) { |bytes_sum, n| bytes_sum + n.encoded_data_length }
end

#onload_eventObject

The number of seconds after start_time that the OnLoad event fired


32
33
34
35
36
37
38
39
# File 'lib/chrome_debugger/document.rb', line 32

def onload_event
  @onload_event ||= begin
                      ts = @events.select { |event|
                        event.is_a?(LoadEventFired)
                      }.slice(0,1).map(&:timestamp).first
                      ts ? (ts - start_time).round(3) : nil
                    end
end

#request_countObject

The number of network requests required to load this document


91
92
93
94
95
# File 'lib/chrome_debugger/document.rb', line 91

def request_count
  @events.select {|n|
    n.is_a?(ResponseReceived)
  }.size
end

#request_count_by_resource(resource_type) ⇒ Object

the number of network requests of a particular resource type that were required to load this document

Possible resource types: 'Document', 'Script', 'Image', 'Stylesheet', 'Other'.


103
104
105
106
107
# File 'lib/chrome_debugger/document.rb', line 103

def request_count_by_resource(resource_type)
  @events.select {|n|
    n.is_a?(ResponseReceived) && n.resource_type == resource_type
  }.size
end

#start_timeObject

The seconds since epoch that the request for this document started


20
21
22
23
24
25
26
27
28
# File 'lib/chrome_debugger/document.rb', line 20

def start_time
  @start_time ||= @events.select { |event|
    event.is_a?(RequestWillBeSent)
  }.select { |event|
    event.request['url'] == @url
  }.map { |event|
    event.timestamp
  }.first
end