Class: Puppeteer::Tracing
- Inherits:
-
Object
- Object
- Puppeteer::Tracing
- Defined in:
- lib/puppeteer/tracing.rb
Constant Summary collapse
- 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
Instance Method Summary collapse
-
#initialize(client) ⇒ Tracing
constructor
A new instance of Tracing.
- #start(path: nil, screenshots: nil, categories: nil) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(client) ⇒ Tracing
Returns a new instance of Tracing.
3 4 5 6 |
# File 'lib/puppeteer/tracing.rb', line 3 def initialize(client) @client = client @recording = false end |
Instance Method Details
#start(path: nil, screenshots: nil, categories: nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/puppeteer/tracing.rb', line 23 def start(path: nil, screenshots: nil, categories: nil) option_categories = categories || DEFAULT_CATEGORIES.dup if screenshots option_categories << 'disabled-by-default-devtools.screenshot' end ex_cat = option_categories.select { |cat| cat.start_with?('-') }.map { |cat| cat[1..-1] } in_cat = option_categories.reject { |cat| cat.start_with?('-') } @path = path @recording = true @client.('Tracing.start', transferMode: 'ReturnAsStream', traceConfig: { excludedCategories: ex_cat, includedCategories: in_cat, }, ) end |
#stop ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/puppeteer/tracing.rb', line 43 def stop stream_promise = resolvable_future do |f| @client.once('Tracing.tracingComplete') do |event| f.fulfill(event['stream']) end end @client.('Tracing.end') @recording = false stream = await stream_promise chunks = Puppeteer::ProtocolStreamReader.new(client: @client, handle: stream).read_as_chunks StringIO.open do |stringio| if @path File.open(@path, 'wb') do |f| chunks.each do |chunk| f.write(chunk) stringio.write(chunk) end end else chunks.each do |chunk| stringio.write(chunk) end end stringio.string end end |