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: '/usr/bin/firefox', }.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
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 111 112 |
# File 'lib/puppeteer/launcher/firefox.rb', line 84 def connect( = {}) = 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: .ignore_https_errors?, default_viewport: ., process: nil, close_callback: -> { connection.('Browser.close') }, ) end |
#default_args(options = nil) ⇒ DefaultArgs
219 220 221 |
# File 'lib/puppeteer/launcher/firefox.rb', line 219 def default_args( = nil) DefaultArgs.new(ChromeArgOptions.new( || {})) end |
#executable_path(channel: nil) ⇒ string
137 138 139 140 141 142 143 |
# File 'lib/puppeteer/launcher/firefox.rb', line 137 def executable_path(channel: nil) if channel executable_path_for_channel(channel.to_s) else executable_path_for_channel('firefox') 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 |
# File 'lib/puppeteer/launcher/firefox.rb', line 14 def launch( = {}) = ChromeArgOptions.new() = LaunchOptions.new() = BrowserOptions.new() firefox_arguments = if !.ignore_default_args default_args().to_a elsif .ignore_default_args.is_a?(Enumerable) default_args().reject do |arg| .ignore_default_args.include?(arg) end.to_a else .args.dup end if firefox_arguments.none? { |arg| arg.start_with?('--remote-debugging-') } firefox_arguments << '--remote-debugging-port=0' end temporary_user_data_dir = nil if firefox_arguments.none? { |arg| arg.start_with?('--profile') || arg.start_with?('-profile') } temporary_user_data_dir = create_profile firefox_arguments << "--profile" firefox_arguments << temporary_user_data_dir end firefox_executable = if .channel executable_path_for_channel(.channel.to_s) else .executable_path || executable_path_for_channel('nightly') end runner = Puppeteer::BrowserRunner.new(firefox_executable, firefox_arguments, temporary_user_data_dir) runner.start( handle_SIGHUP: .handle_SIGHUP?, handle_SIGTERM: .handle_SIGTERM?, handle_SIGINT: .handle_SIGINT?, dumpio: .dumpio?, env: .env, pipe: .pipe?, ) begin connection = runner.setup_connection( use_pipe: .pipe?, timeout: .timeout, slow_mo: .slow_mo, preferred_revision: @preferred_revision, ) browser = Puppeteer::Browser.create( connection: connection, context_ids: [], ignore_https_errors: .ignore_https_errors?, default_viewport: ., process: runner.proc, close_callback: -> { runner.close }, ) browser.wait_for_target(predicate: ->(target) { target.type == 'page' }) browser rescue runner.kill raise end end |
#product ⇒ Object
174 175 176 |
# File 'lib/puppeteer/launcher/firefox.rb', line 174 def product 'firefox' end |