Sha256: 663c784c7e43d5e2fa83729e01712a75c7563e51345ea3cacb5d5d2ea0a30af3

Contents?: true

Size: 1.28 KB

Versions: 7

Compression:

Stored size: 1.28 KB

Contents

class Puppeteer::Tracing
  # @param client [Puppeteer::CDPSession]
  def initialize(client)
    @client = client
    @recording = false
  end

  DEFAULT_CATEGORIES = [
    '-*',
    'devtools.timeline',
    'v8.execute',
    'disabled-by-default-devtools.timeline',
    'disabled-by-default-devtools.timeline.frame',
    'toplevel',
    'blink.console',
    'blink.user_timing',
    'latencyInfo',
    'disabled-by-default-devtools.timeline.stack',
    'disabled-by-default-v8.cpu_profiler',
    'disabled-by-default-v8.cpu_profiler.hires',
  ].freeze

  def start(path: nil, screenshots: nil, categories: nil)
    option_categories = categories || DEFAULT_CATEGORIES.dup

    if screenshots
      option_categories << 'disabled-by-default-devtools.screenshot'
    end

    @path = path
    @recording = true
    @client.send_message('Tracing.start',
      transferMode: 'ReturnAsStream',
      categories: option_categories.join(','),
    )
  end

  def stop
    stream_promise = resolvable_future do |f|
      @client.once('Tracing.tracingComplete') do |event|
        f.fulfill(event['stream'])
      end
    end
    @client.send_message('Tracing.end')
    @recording = false

    stream = await stream_promise
    Puppeteer::ProtocolStreamReader.new(client: @client, handle: stream, path: @path).read
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
puppeteer-ruby-0.34.0 lib/puppeteer/tracing.rb
puppeteer-ruby-0.33.0 lib/puppeteer/tracing.rb
puppeteer-ruby-0.32.4 lib/puppeteer/tracing.rb
puppeteer-ruby-0.32.3 lib/puppeteer/tracing.rb
puppeteer-ruby-0.32.2 lib/puppeteer/tracing.rb
puppeteer-ruby-0.32.1 lib/puppeteer/tracing.rb
puppeteer-ruby-0.32.0 lib/puppeteer/tracing.rb