File tree Expand file tree Collapse file tree 3 files changed +54
-2
lines changed
Expand file tree Collapse file tree 3 files changed +54
-2
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,6 @@ class Options
66 class Chrome < Base
77 DEFAULT_OPTIONS = {
88 "headless" => nil ,
9- "disable-gpu" => nil ,
109 "hide-scrollbars" => nil ,
1110 "mute-audio" => nil ,
1211 "enable-automation" => nil ,
@@ -43,7 +42,18 @@ class Chrome < Base
4342 # NOTE: --no-sandbox is not needed if you properly setup a user in the container.
4443 # https://github.com/ebidel/lighthouse-ci/blob/master/builder/Dockerfile#L35-L40
4544 # "no-sandbox" => nil,
46- } . freeze
45+ }
46+ # On Windows, the --disable-gpu flag is a temporary work around for a few bugs.
47+ # See crbug.com/737678 for more information.
48+ if Utils ::Platform . windows?
49+ DEFAULT_OPTIONS . merge! ( "disable-gpu" => nil )
50+ end
51+ # Use Metal on Apple Silicon
52+ # https://github.com/google/angle#platform-support-via-backing-renderers
53+ if Utils ::Platform . mac_arm?
54+ DEFAULT_OPTIONS . merge! ( "use-angle" => "metal" )
55+ end
56+ DEFAULT_OPTIONS . freeze
4757
4858 MAC_BIN_PATH = [
4959 "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" ,
Original file line number Diff line number Diff line change @@ -20,6 +20,10 @@ def mac?
2020 RbConfig ::CONFIG [ "host_os" ] =~ /darwin/
2121 end
2222
23+ def mac_arm?
24+ mac? && RbConfig ::CONFIG [ "host_cpu" ] =~ /arm/
25+ end
26+
2327 def mri?
2428 defined? ( RUBY_ENGINE ) && RUBY_ENGINE == "ruby"
2529 end
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ describe Ferrum ::Browser ::Options ::Chrome do
4+ def reload_chrome_class
5+ described_class . constants ( false ) . each do |const |
6+ described_class . send ( :remove_const , const )
7+ end
8+ load 'ferrum/browser/options/chrome.rb'
9+ end
10+
11+ describe "DEFAULT_OPTIONS" do
12+ it "includes `disable-gpu` flag only on windows" do
13+ allow ( Ferrum ::Utils ::Platform ) . to receive ( :windows? ) . and_return ( true )
14+ reload_chrome_class
15+ expect ( described_class ::DEFAULT_OPTIONS ) . to include ( "disable-gpu" => nil )
16+
17+ allow ( Ferrum ::Utils ::Platform ) . to receive ( :windows? ) . and_return ( false )
18+ reload_chrome_class
19+ expect ( described_class ::DEFAULT_OPTIONS ) . not_to include ( "disable-gpu" => nil )
20+
21+ allow ( Ferrum ::Utils ::Platform ) . to receive ( :windows? ) . and_call_original
22+ reload_chrome_class
23+ end
24+
25+ it "includes `use-angle=metal` flag only on mac arm" do
26+ allow ( Ferrum ::Utils ::Platform ) . to receive ( :mac_arm? ) . and_return ( true )
27+ reload_chrome_class
28+ expect ( described_class ::DEFAULT_OPTIONS ) . to include ( "use-angle" => "metal" )
29+
30+ allow ( Ferrum ::Utils ::Platform ) . to receive ( :mac_arm? ) . and_return ( false )
31+ reload_chrome_class
32+ expect ( described_class ::DEFAULT_OPTIONS ) . not_to include ( "use-angle" => "metal" )
33+
34+ allow ( Ferrum ::Utils ::Platform ) . to receive ( :mac_arm? ) . and_call_original
35+ reload_chrome_class
36+ end
37+ end
38+ end
You can’t perform that action at this time.
0 commit comments