From 681489c6ff411688987f2b39e277715d613a9920 Mon Sep 17 00:00:00 2001 From: Erick Guan Date: Wed, 27 Dec 2023 08:22:14 +0100 Subject: [PATCH] chroe: inspect browser classes (#428) --- lib/ferrum/browser/client.rb | 7 +++++++ lib/ferrum/browser/command.rb | 4 ++++ lib/ferrum/browser/process.rb | 11 +++++++++++ 3 files changed, 22 insertions(+) diff --git a/lib/ferrum/browser/client.rb b/lib/ferrum/browser/client.rb index e1136504..97342227 100644 --- a/lib/ferrum/browser/client.rb +++ b/lib/ferrum/browser/client.rb @@ -70,6 +70,13 @@ def close @thread.kill unless @thread.join(1) end + def inspect + "#<#{self.class} " \ + "@command_id=#{@command_id.inspect} " \ + "@pendings=#{@pendings.inspect} " \ + "@ws=#{@ws.inspect}>" + end + private def build_message(method, params) diff --git a/lib/ferrum/browser/command.rb b/lib/ferrum/browser/command.rb index e86649d3..b6907cec 100644 --- a/lib/ferrum/browser/command.rb +++ b/lib/ferrum/browser/command.rb @@ -47,6 +47,10 @@ def to_a [path] + @flags.map { |k, v| v.nil? ? "--#{k}" : "--#{k}=#{v}" } end + def to_s + to_a.join(" \\ \n ") + end + private def merge_options diff --git a/lib/ferrum/browser/process.rb b/lib/ferrum/browser/process.rb index b3a22483..3c6e9c88 100644 --- a/lib/ferrum/browser/process.rb +++ b/lib/ferrum/browser/process.rb @@ -122,6 +122,17 @@ def restart start end + def inspect + "#<#{self.class} " \ + "@user_data_dir=#{@user_data_dir.inspect} " \ + "@command=#<#{@command.class}:#{@command.object_id}> " \ + "@default_user_agent=#{@default_user_agent.inspect} " \ + "@ws_url=#{@ws_url.inspect} " \ + "@v8_version=#{@v8_version.inspect} " \ + "@browser_version=#{@browser_version.inspect} " \ + "@webkit_version=#{@webkit_version.inspect}>" + end + private def kill(pid)