rubycdp / ferrum

Headless Chrome Ruby API
https://ferrum.rubycdp.com
MIT License
1.74k stars 123 forks source link

Remove `disable-gpu`default flag for Apple Silicon #421

Closed thibaudgg closed 8 months ago

thibaudgg commented 10 months ago

The disable-gpu is part of the default Chrome options but it is causing issues with webpages using WebGL on Apple Silicon machine.

I was able to make it work by removing the disable-gpu flag and adding the --use-angle=metal flag via this small monkey-patch:

# Enable GPU (with Metal) for Chrome on Apple Silicon
if Gem::Platform.local.cpu == "arm64" && Gem::Platform.local.os == "darwin"
  chrome_class = Ferrum::Browser::Options::Chrome
  default_options = chrome_class::DEFAULT_OPTIONS.dup

  default_options.delete('disable-gpu')
  default_options['use-angle'] = 'metal'

  chrome_class.send(:remove_const, 'DEFAULT_OPTIONS')
  chrome_class::DEFAULT_OPTIONS = default_options.freeze
end

Do you think this should be set by default for Apple Silicon, or at least stop adding the disable-gpu flag on this platform? I'm happy to provide a PR if needed.

route commented 9 months ago

From https://developer.chrome.com/blog/headless-chrome

Do I need the --disable-gpu flag?

Only on Windows. Other platforms no longer require it. The --disable-gpu flag is a temporary work around for a few bugs. You won't need this flag in future versions of Chrome. See crbug.com/737678 for more information.

So you are right, we need to add some conditionals for windows and mac most likely. Mind sending a PR?

thibaudgg commented 8 months ago

@route sure things, just created a PR for it: https://github.com/rubycdp/ferrum/pull/436

route commented 8 months ago

Thanks!