Class: Puppeteer::Launcher::Firefox
- Inherits:
-
Object
- Object
- Puppeteer::Launcher::Firefox
- Defined in:
- lib/puppeteer/launcher/firefox.rb
Defined Under Namespace
Classes: DefaultArgs
Constant Summary collapse
- FIREFOX_EXECUTABLE_PATHS =
{ windows: "#{ENV['PROGRAMFILES']}\\Firefox Nightly\\firefox.exe", darwin: '/Applications/Firefox Nightly.app/Contents/MacOS/firefox', linux: -> { Puppeteer::ExecutablePathFinder.new('firefox').find_first }, }.freeze
Instance Method Summary collapse
- #connect(options = {}) ⇒ Puppeteer::Browser
- #default_args(options = nil) ⇒ DefaultArgs
- #executable_path(channel: nil) ⇒ string
-
#initialize(project_root:, preferred_revision:, is_puppeteer_core:) ⇒ Firefox
constructor
A new instance of Firefox.
- #launch(options = {}) ⇒ !Promise<!Browser>
- #product ⇒ Object
Constructor Details
#initialize(project_root:, preferred_revision:, is_puppeteer_core:) ⇒ Firefox
Returns a new instance of Firefox.
6 7 8 9 10 |
# File 'lib/puppeteer/launcher/firefox.rb', line 6 def initialize(project_root:, preferred_revision:, is_puppeteer_core:) @project_root = project_root @preferred_revision = preferred_revision @is_puppeteer_core = is_puppeteer_core end |
Instance Method Details
#connect(options = {}) ⇒ Puppeteer::Browser
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/puppeteer/launcher/firefox.rb', line 108 def connect( = {}) @browser_options = BrowserOptions.new() browser_ws_endpoint = [:browser_ws_endpoint] browser_url = [:browser_url] transport = [:transport] connection = if browser_ws_endpoint && browser_url.nil? && transport.nil? connect_with_browser_ws_endpoint(browser_ws_endpoint) elsif browser_ws_endpoint.nil? && browser_url && transport.nil? connect_with_browser_url(browser_url) elsif browser_ws_endpoint.nil? && browser_url.nil? && transport connect_with_transport(transport) else raise ArgumentError.new("Exactly one of browserWSEndpoint, browserURL or transport must be passed to puppeteer.connect") end result = connection.('Target.getBrowserContexts') browser_context_ids = result['browserContextIds'] Puppeteer::Browser.create( connection: connection, context_ids: browser_context_ids, ignore_https_errors: @browser_options.ignore_https_errors?, default_viewport: @browser_options., process: nil, close_callback: -> { connection.('Browser.close') }, ) end |
#default_args(options = nil) ⇒ DefaultArgs
252 253 254 |
# File 'lib/puppeteer/launcher/firefox.rb', line 252 def default_args( = nil) DefaultArgs.new(ChromeArgOptions.new( || {})) end |
#executable_path(channel: nil) ⇒ string
161 162 163 164 165 166 167 |
# File 'lib/puppeteer/launcher/firefox.rb', line 161 def executable_path(channel: nil) if channel executable_path_for_channel(channel.to_s) else fallback_executable_path end end |
#launch(options = {}) ⇒ !Promise<!Browser>
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 |
# File 'lib/puppeteer/launcher/firefox.rb', line 14 def launch( = {}) @chrome_arg_options = ChromeArgOptions.new() @launch_options = LaunchOptions.new() @browser_options = BrowserOptions.new() firefox_arguments = if !@launch_options.ignore_default_args default_args().to_a elsif @launch_options.ignore_default_args.is_a?(Enumerable) default_args().reject do |arg| @launch_options.ignore_default_args.include?(arg) end.to_a else @chrome_arg_options.args.dup end if firefox_arguments.none? { |arg| arg.start_with?('--remote-debugging-') } firefox_arguments << "--remote-debugging-port=#{@chrome_arg_options.debugging_port}" end profile_arg_index = firefox_arguments.index { |arg| arg.start_with?('--profile') || arg.start_with?('-profile') } if profile_arg_index using_temp_user_data_dir = false user_data_dir = firefox_arguments[profile_arg_index + 1] unless File.exist?(user_data_dir) raise ArgumentError.new("Firefox profile not found at '#{user_data_dir}'") end prefs = default_preferences(@launch_options.extra_prefs_firefox) write_preferences(prefs, user_data_dir) else using_temp_user_data_dir = true user_data_dir = create_profile(@launch_options.extra_prefs_firefox) firefox_arguments << "--profile" firefox_arguments << user_data_dir end firefox_executable = if @launch_options.channel executable_path_for_channel(@launch_options.channel.to_s) else @launch_options.executable_path || fallback_executable_path end runner = Puppeteer::BrowserRunner.new( true, firefox_executable, firefox_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: @launch_options.pipe?, ) browser = begin connection = runner.setup_connection( use_pipe: @launch_options.pipe?, timeout: @launch_options.timeout, slow_mo: @browser_options.slow_mo, preferred_revision: @preferred_revision, ) Puppeteer::Browser.create( connection: connection, context_ids: [], ignore_https_errors: @browser_options.ignore_https_errors?, default_viewport: @browser_options., process: runner.proc, close_callback: -> { runner.close }, ) 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 |
#product ⇒ Object
205 206 207 |
# File 'lib/puppeteer/launcher/firefox.rb', line 205 def product 'firefox' end |