From 2a11abde9bfdd437dd01e4e478d96dadb4a26443 Mon Sep 17 00:00:00 2001 From: YusukeIwaki Date: Fri, 13 Sep 2024 06:31:23 +0900 Subject: [PATCH] Fix launch parameters for Firefox >= 129. --- lib/puppeteer/browser_runner.rb | 4 +++ lib/puppeteer/launcher/firefox.rb | 57 +++++++++++++++++++++++-------- spec/integration/launcher_spec.rb | 8 ++--- 3 files changed, 51 insertions(+), 18 deletions(-) diff --git a/lib/puppeteer/browser_runner.rb b/lib/puppeteer/browser_runner.rb index b232b94..0221623 100644 --- a/lib/puppeteer/browser_runner.rb +++ b/lib/puppeteer/browser_runner.rb @@ -178,6 +178,10 @@ def setup_connection(use_pipe:, timeout:, slow_mo:, preferred_revision:) Timeout.timeout(timeout / 1000.0) do loop do line = browser_process.stderr.readline + /^WebDriver BiDi listening on (ws:\/\/.*)$/.match(line) do |m| + raise NotImplementedError.new('WebDriver BiDi support is not yet implemented') + end + /^DevTools listening on (ws:\/\/.*)$/.match(line) do |m| return m[1].gsub(/\r/, '') end diff --git a/lib/puppeteer/launcher/firefox.rb b/lib/puppeteer/launcher/firefox.rb index 55413d3..97abd5a 100644 --- a/lib/puppeteer/launcher/firefox.rb +++ b/lib/puppeteer/launcher/firefox.rb @@ -122,7 +122,11 @@ def executable_path(channel: nil) FIREFOX_EXECUTABLE_PATHS = { windows: "#{ENV['PROGRAMFILES']}\\Firefox Nightly\\firefox.exe", - darwin: '/Applications/Firefox Nightly.app/Contents/MacOS/firefox', + darwin: -> { + ['Firefox Nightly.app', 'Firefox Developer Edition.app'].map do |app| + "/Applications/#{app}/Contents/MacOS/firefox" + end.find { |path| File.exist?(path) } + }, linux: -> { Puppeteer::ExecutablePathFinder.new('firefox').find_first }, }.freeze @@ -161,7 +165,7 @@ class DefaultArgs # @param options [Launcher::ChromeArgOptions] def initialize(chrome_arg_options) - firefox_arguments = ['--no-remote'] + firefox_arguments = [] if Puppeteer.env.darwin? firefox_arguments << '--foreground' @@ -236,7 +240,6 @@ def default_args(options = nil) 'browser.safebrowsing.blockedURIs.enabled': false, 'browser.safebrowsing.downloads.enabled': false, 'browser.safebrowsing.malware.enabled': false, - 'browser.safebrowsing.passwords.enabled': false, 'browser.safebrowsing.phishing.enabled': false, # Disable updates to search engines. @@ -262,6 +265,9 @@ def default_args(options = nil) # Do not warn when multiple tabs will be opened 'browser.tabs.warnOnOpen': false, + # Do not automatically offer translations, as tests do not expect this. + 'browser.translations.automaticallyPopup': false, + # Disable the UI tour. 'browser.uitour.enabled': false, # Turn off search suggestions in the location bar so as not to trigger @@ -324,30 +330,33 @@ def default_args(options = nil) # Make sure opening about:addons will not hit the network 'extensions.webservice.discoverURL': "http://#{server}/dummy/discoveryURL", - # Temporarily force disable BFCache in parent (https://bit.ly/bug-1732263) - 'fission.bfcacheInParent': false, - # Force all web content to use a single content process - 'fission.webContentIsolationStrategy': 0, - # Allow the application to have focus even it runs in the background 'focusmanager.testmode': true, + # Disable useragent updates 'general.useragent.updates.enabled': false, + # Always use network provider for geolocation tests so we bypass the # macOS dialog raised by the corelocation provider 'geo.provider.testing': true, + # Do not scan Wifi 'geo.wifi.scan': false, + # No hang monitor 'hangmonitor.timeout': 0, + # Show chrome errors and warnings in the error console 'javascript.options.showInConsole': true, # Disable download and usage of OpenH264: and Widevine plugins 'media.gmp-manager.updateEnabled': false, - # Prevent various error message on the console - # jest-puppeteer asserts that no error message is emitted by the console - 'network.cookie.cookieBehavior': 0, + + # Disable the GFX sanity window + 'media.sanity-test.disabled': true, + + # Disable experimental feature that is only available in Nightly + 'network.cookie.sameSite.laxByDefault': false, # Do not prompt for temporary redirects 'network.http.prompt-temp-redirect': false, @@ -367,15 +376,17 @@ def default_args(options = nil) 'privacy.trackingprotection.enabled': false, - # Enable Remote Agent - # https://bugzilla.mozilla.org/show_bug.cgi?id=1544393 + # Can be removed once Firefox 89 is no longer supported + # https://bugzilla.mozilla.org/show_bug.cgi?id=1710839 'remote.enabled': true, # Don't do network connections for mitm priming 'security.certerrors.mitm.priming.enabled': false, + # Local documents have access to all other local documents, # including directory listings 'security.fileuri.strict_origin_policy': false, + # Do not wait for the notification button security delay 'security.notification_enable_delay': 0, @@ -385,6 +396,7 @@ def default_args(options = nil) # Do not automatically fill sign-in forms with known usernames and # passwords 'signon.autofillForms': false, + # Disable password capture, so that tests that include forms are not # influenced by the presence of the persistent doorhanger notification 'signon.rememberSignons': false, @@ -400,7 +412,24 @@ def default_args(options = nil) # Prevent starting into safe mode after application crashes 'toolkit.startup.max_resumed_crashes': -1, - } + }.merge({ + # Do not close the window when the last tab gets closed + 'browser.tabs.closeWindowWithLastTab': false, + # Prevent various error message on the console + # jest-puppeteer asserts that no error message is emitted by the console + 'network.cookie.cookieBehavior': 0, + # Temporarily force disable BFCache in parent (https://bit.ly/bug-1732263) + 'fission.bfcacheInParent': false, + # Only enable the CDP protocol + 'remote.active-protocols': 2, + }).merge({ + # Force all web content to use a single content process. TODO: remove + # this once Firefox supports mouse event dispatch from the main frame + # context. Once this happens, webContentIsolationStrategy should only + # be set for CDP. See + # https://bugzilla.mozilla.org/show_bug.cgi?id=1773393 + 'fission.webContentIsolationStrategy': 0, + }) default_preferences.merge(extra_prefs) end diff --git a/spec/integration/launcher_spec.rb b/spec/integration/launcher_spec.rb index 5c23a31..f78f86b 100644 --- a/spec/integration/launcher_spec.rb +++ b/spec/integration/launcher_spec.rb @@ -307,13 +307,13 @@ if Puppeteer.env.firefox? expected_args = if Puppeteer.env.darwin? - %w(--headless --no-remote --foreground) + %w(--headless --foreground) elsif Puppeteer.env.windows? - %w(--headless --no-remote --wait-for-browser) + %w(--headless --wait-for-browser) else - %w(--headless --no-remote) + %w(--headless) end - unexpected_args = %w(--headless --no-remote --foreground --wait-for-browser) - expected_args + unexpected_args = %w(--headless --foreground --wait-for-browser) - expected_args expect(Puppeteer.default_args).to include(*expected_args) expect(Puppeteer.default_args).not_to include(*unexpected_args) else