Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I add a custom Chrome command-line argument? #619

Closed
mildmojo opened this issue Jul 10, 2020 · 14 comments
Closed

How do I add a custom Chrome command-line argument? #619

mildmojo opened this issue Jul 10, 2020 · 14 comments
Labels
enhancement Making things better

Comments

@mildmojo
Copy link

mildmojo commented Jul 10, 2020

I have a Python project using SeleniumBase 1.34.11 that's running inside a docker container, and I'm forwarding my pytest run to the X server on my Linux host. Unfortunately, Chrome v79 has a bug that makes it render a blank window to my host X server (nothing, no UI at all).

In the Chromium project bug report, one commenter suggests starting Chrome with --use-gl=swiftshader to enable software rendering. This works for me; I can run google-chrome --use-gl=swiftshader, and I get a regular Chome window with full UI.

I'd like to send that argument to Chrome via SeleniumBase. I've looked through the documentation and the issues in this repo, but I don't see any mention or examples of custom Chrome options. In the codebase, I see where the browser launcher's _set_chrome_options gets a ChromeOptions object and sets arguments on it, but it seems like it only understands hardcoded arguments.

Is there a way to add a custom Chrome command-line argument?

@mdmintz
Copy link
Member

mdmintz commented Jul 10, 2020

@mildmojo I'll create a new release of SeleniumBase with that option enabled. I don't see why it would hurt to have it on all the time.

@mdmintz
Copy link
Member

mdmintz commented Jul 10, 2020

@mildmojo I added the Chrome option you wanted in version 1.42.9
chrome_options.add_argument("--use-gl=swiftshader")
https://github.com/seleniumbase/SeleniumBase/releases/tag/v1.42.9

@mdmintz
Copy link
Member

mdmintz commented Jul 10, 2020

Chrome options are all set here: https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/core/browser_launcher.py
From the command line, you can alter some of them with pytest arguments, which are defined here: https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/plugins/pytest_plugin.py
If there's another option you need that isn't there, I can add that into anther release. swiftshader is now there if you upgrade to v1.42.9

@mildmojo
Copy link
Author

That's great! Thank you for the lightning-quick feature add! 🎉

I'll see about upgrading my project on Monday.

@mildmojo
Copy link
Author

One note, in the bug report I linked above, the commenter saw a performance penalty in their case. It might adversely affect non-headless users who have GPUs available? It could be worth leaving off by default, with like a --swiftshader option to enable it?

@mdmintz
Copy link
Member

mdmintz commented Jul 10, 2020

@mildmojo Good idea. I'll create another release using --swiftshader to enable it so that it's not on by default.

@mildmojo
Copy link
Author

mildmojo commented Jul 10, 2020 via email

@mdmintz
Copy link
Member

mdmintz commented Jul 11, 2020

@mildmojo See https://github.com/seleniumbase/SeleniumBase/releases/tag/v1.42.10
Now, swiftshader is only enabled when specified as a command-line option:
--swiftshader

@mildmojo
Copy link
Author

mildmojo commented Jul 11, 2020 via email

@mildmojo
Copy link
Author

mildmojo commented Jul 13, 2020

@mdmintz I had a chance to test this today, and it looks like Chrome treats the swiftshader software renderer as a GPU, which means the always-on --disable-gpu Chrome flag disables the swiftshader renderer, and I still see a blank window with the new --swiftshader option turned on.

I confirmed by capturing the full pytest/seleniumbase-composed Chrome command line in the /opt/google/chrome/chrome.real shell script, then whittling the CLI flags down to a minimal case that worked or didn't work. I'm seeing --disable-gpu --use-gl=swiftshader rendering a blank window, and --use-gl=swiftshader alone rendering a proper window. I can see swiftshader info in about:gpu when it's working, too.

Would you be willing to omit --disable-gpu when --swiftshader is specified?

@mdmintz
Copy link
Member

mdmintz commented Jul 13, 2020

@mildmojo Sounds good. I'll create a new release with the update.

@mdmintz
Copy link
Member

mdmintz commented Jul 14, 2020

@mildmojo OK, it's ready in SeleniumBase v1.42.12
https://github.com/seleniumbase/SeleniumBase/releases/tag/v1.42.12

@mildmojo
Copy link
Author

mildmojo commented Jul 14, 2020 via email

@mdmintz mdmintz added the enhancement Making things better label Jul 17, 2020
@mildmojo
Copy link
Author

@mdmintz AFAICT, the --swiftshader option (and the way it now turns off --disable-gpu) is doing the right thing, and gets me a working Chrome v79 display when forwarded to my host X server.

I also tested with dockerized Xpra and Xvfb+x11vnc+VNC setups, and while they had their own issues, Chrome rendering is fixed.

Thanks again for the quick, solid help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Making things better
Projects
None yet
Development

No branches or pull requests

2 participants