Sha256: 525db65baf028719c4f0e24ecd49c5ed3db50d42519dd9c8420996b70099dd2c

Contents?: true

Size: 1.12 KB

Versions: 33

Compression:

Stored size: 1.12 KB

Contents

class Puppeteer::Page
  class Metrics
    SUPPORTED_KEYS = Set.new([
      'Timestamp',
      'Documents',
      'Frames',
      'JSEventListeners',
      'Nodes',
      'LayoutCount',
      'RecalcStyleCount',
      'LayoutDuration',
      'RecalcStyleDuration',
      'ScriptDuration',
      'TaskDuration',
      'JSHeapUsedSize',
      'JSHeapTotalSize',
    ]).freeze

    SUPPORTED_KEYS.each do |key|
      attr_reader key
    end

    # @param metrics_result [Hash] response for Performance.getMetrics
    def initialize(metrics_response)
      metrics_response.each do |metric|
        if SUPPORTED_KEYS.include?(metric['name'])
          instance_variable_set(:"@#{metric['name']}", metric['value'])
        end
      end
    end

    def [](key)
      if SUPPORTED_KEYS.include?(key.to_s)
        instance_variable_get(:"@#{key}")
      else
        raise ArgumentError.new("invalid metric key specified: #{key}")
      end
    end
  end

  class MetricsEvent
    def initialize(metrics_event)
      @title = metrics_event['title']
      @metrics = Metrics.new(metrics_event['metrics'])
    end

    attr_reader :title, :metrics
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
puppeteer-ruby-0.45.6 lib/puppeteer/page/metrics.rb
puppeteer-ruby-0.45.5 lib/puppeteer/page/metrics.rb
puppeteer-ruby-0.45.4 lib/puppeteer/page/metrics.rb
puppeteer-ruby-0.45.3 lib/puppeteer/page/metrics.rb
puppeteer-ruby-0.45.2 lib/puppeteer/page/metrics.rb
puppeteer-ruby-0.45.2.alpha2 lib/puppeteer/page/metrics.rb
puppeteer-ruby-0.45.2.alpha1 lib/puppeteer/page/metrics.rb
puppeteer-ruby-0.45.1 lib/puppeteer/page/metrics.rb
puppeteer-ruby-0.45.0 lib/puppeteer/page/metrics.rb
puppeteer-ruby-0.44.3 lib/puppeteer/page/metrics.rb
puppeteer-ruby-0.44.2 lib/puppeteer/page/metrics.rb
puppeteer-ruby-0.44.1 lib/puppeteer/page/metrics.rb
puppeteer-ruby-0.44.0 lib/puppeteer/page/metrics.rb
puppeteer-ruby-0.43.1 lib/puppeteer/page/metrics.rb
puppeteer-ruby-0.43.0 lib/puppeteer/page/metrics.rb
puppeteer-ruby-0.42.0 lib/puppeteer/page/metrics.rb
puppeteer-ruby-0.41.0 lib/puppeteer/page/metrics.rb
puppeteer-ruby-0.40.7 lib/puppeteer/page/metrics.rb
puppeteer-ruby-0.40.6 lib/puppeteer/page/metrics.rb
puppeteer-ruby-0.40.5 lib/puppeteer/page/metrics.rb