Class: Bidi2pdf::SessionRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/bidi2pdf/session_runner.rb

Overview

Represents a runner for managing browser sessions and executing tasks using the Bidi2pdf library. This class handles the setup, configuration, and execution of browser-related workflows, including navigation, cookie management, and printing.

Examples:

Running a session

session_runner = Bidi2pdf::SessionRunner.new(
  session: session,
  url: "http://example.com",
  inputfile: "input.html",
  output: "output.pdf",
  cookies: { "key" => "value" },
  headers: { "Authorization" => "Bearer token" },
  auth: { username: "user", password: "pass" },
  wait_window_loaded: true,
  wait_network_idle: true,
  print_options: { landscape: true },
  network_log_format: :json
)
session_runner.run

Instance Method Summary collapse

Constructor Details

#initialize(session:, url:, inputfile:, output:, cookies: {}, headers: {}, auth: {}, wait_window_loaded: false, wait_network_idle: false, print_options: {}, network_log_format: :console) ⇒ SessionRunner

rubocop: disable Metrics/ParameterLists



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/bidi2pdf/session_runner.rb', line 38

def initialize(session:, url:, inputfile:, output:, cookies: {}, headers: {}, auth: {}, wait_window_loaded: false,
               wait_network_idle: false, print_options: {}, network_log_format: :console)
  @session = session
  @url = url
  @inputfile = inputfile
  @output = output
  @cookies = cookies || {}
  @headers = headers || {}
  @auth = auth || {}
  @wait_window_loaded = wait_window_loaded
  @wait_network_idle = wait_network_idle
  @print_options = print_options || {}
  @network_log_format = network_log_format
end

Instance Method Details

#runObject

rubocop: enable Metrics/ParameterLists



55
56
57
58
59
60
61
# File 'lib/bidi2pdf/session_runner.rb', line 55

def run
  @session.start
  @session.client.on_close { Bidi2pdf.logger.info "WebSocket closed" }

  setup_browser
  run_flow
end