Skip to content

Commit

Permalink
Fix launch parameters for Firefox >= 129.
Browse files Browse the repository at this point in the history
  • Loading branch information
YusukeIwaki committed Sep 12, 2024
1 parent 89f44c6 commit 2a11abd
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 18 deletions.
4 changes: 4 additions & 0 deletions lib/puppeteer/browser_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 43 additions & 14 deletions lib/puppeteer/launcher/firefox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,

Expand All @@ -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,
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions spec/integration/launcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2a11abd

Please sign in to comment.