Class: Bidi2pdf::Launcher

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

Overview

Represents a launcher for managing browser sessions and executing tasks using the Bidi2pdf library. This class handles the setup and teardown of browser sessions, as well as the execution of tasks within those sessions.

Examples:

Launching a session

launcher = Bidi2pdf::Launcher.new(
  url: "http://example.com",
  inputfile: "input.pdf",
  output: "output.pdf",
  cookies: [],
  headers: {},
  auth: nil,
  headless: true
)
launcher.launch
launcher.stop

Instance Method Summary collapse

Constructor Details

#initialize(url:, inputfile:, output:, cookies:, headers:, auth:, headless: true, port: 0, wait_window_loaded: false, wait_network_idle: false, print_options: {}, remote_browser_url: nil, network_log_format: :console) ⇒ Launcher

rubocop:disable Metrics/ParameterLists



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/bidi2pdf/launcher.rb', line 40

def initialize(url:, inputfile:, output:, cookies:, headers:, auth:, headless: true, port: 0, wait_window_loaded: false,
               wait_network_idle: false, print_options: {}, remote_browser_url: nil, network_log_format: :console)
  @url = url
  @inputfile = inputfile
  @port = port
  @headless = headless
  @output = output
  @cookies = cookies
  @headers = headers
  @auth = auth
  @manager = nil
  @wait_window_loaded = wait_window_loaded
  @wait_network_idle = wait_network_idle
  @print_options = print_options || {}
  @remote_browser_url = remote_browser_url
  @custom_session = nil
  @network_log_format = network_log_format
end

Instance Method Details

#launchObject

rubocop:enable Metrics/ParameterLists



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/bidi2pdf/launcher.rb', line 61

def launch
  runner = SessionRunner.new(
    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
  )
  runner.run
end

#stopObject



78
79
80
81
# File 'lib/bidi2pdf/launcher.rb', line 78

def stop
  @manager&.stop
  @custom_session&.close
end