14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/puppeteer/launcher/chrome.rb', line 14
def launch(options = {})
@chrome_arg_options = ChromeArgOptions.new(options)
@launch_options = LaunchOptions.new(options)
@browser_options = BrowserOptions.new(options)
chrome_arguments =
if !@launch_options.ignore_default_args
default_args(options).to_a
elsif @launch_options.ignore_default_args.is_a?(Enumerable)
default_args(options).reject do |arg|
@launch_options.ignore_default_args.include?(arg)
end.to_a
else
@chrome_arg_options.args.dup
end
if chrome_arguments.none? { |arg| arg.start_with?('--remote-debugging-') }
if @launch_options.pipe?
chrome_arguments << '--remote-debugging-pipe'
else
chrome_arguments << "--remote-debugging-port=#{@chrome_arg_options.debugging_port}"
end
end
user_data_dir = chrome_arguments.find { |arg| arg.start_with?('--user-data-dir') }
if user_data_dir
user_data_dir = user_data_dir.split('=').last
unless File.exist?(user_data_dir)
raise ArgumentError.new("Chrome user data dir not found at '#{user_data_dir}'")
end
using_temp_user_data_dir = false
else
user_data_dir = Dir.mktmpdir('puppeteer_dev_chrome_profile-', ENV['PUPPETEER_TMP_DIR'])
chrome_arguments << "--user-data-dir=#{user_data_dir}"
using_temp_user_data_dir = true
end
chrome_executable =
if @launch_options.channel
executable_path_for_channel(@launch_options.channel.to_s)
else
@launch_options.executable_path || fallback_executable_path
end
use_pipe = chrome_arguments.include?('--remote-debugging-pipe')
runner = Puppeteer::BrowserRunner.new(
false,
chrome_executable,
chrome_arguments,
user_data_dir,
using_temp_user_data_dir,
)
runner.start(
handle_SIGHUP: @launch_options.handle_SIGHUP?,
handle_SIGTERM: @launch_options.handle_SIGTERM?,
handle_SIGINT: @launch_options.handle_SIGINT?,
dumpio: @launch_options.dumpio?,
env: @launch_options.env,
pipe: use_pipe,
)
browser =
begin
connection = runner.setup_connection(
use_pipe: use_pipe,
timeout: @launch_options.timeout,
slow_mo: @browser_options.slow_mo,
preferred_revision: @preferred_revision,
)
Puppeteer::Browser.create(
product: product,
connection: connection,
context_ids: [],
ignore_https_errors: @browser_options.ignore_https_errors?,
default_viewport: @browser_options.default_viewport,
process: runner.proc,
close_callback: -> { runner.close },
target_filter_callback: nil,
is_page_target_callback: nil,
)
rescue
runner.kill
raise
end
begin
browser.wait_for_target(
predicate: ->(target) { target.type == 'page' },
timeout: @launch_options.timeout,
)
rescue
browser.close
raise
end
browser
end
|