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

Documenting the selenium-stealth integration with UC Mode #2404

Open
mdmintz opened this issue Dec 31, 2023 · 4 comments
Open

Documenting the selenium-stealth integration with UC Mode #2404

mdmintz opened this issue Dec 31, 2023 · 4 comments
Assignees
Labels
documentation UC Mode Undetected Chromedriver Mode (--uc)

Comments

@mdmintz
Copy link
Member

mdmintz commented Dec 31, 2023

Documenting the selenium-stealth integration with UC Mode

(Info: selenium-stealth lets you mask your web browser's fingerprint and WebGL information.)

Prerequisites: selenium-stealth must be installed separately: pip install selenium-stealth

Here's an example of the selenium-stealth integration with the Driver() manager and UC Mode:

from seleniumbase import Driver
from selenium_stealth import stealth

driver = Driver(uc=True)
stealth(
    driver,
    languages=["en-US", "en"],
    vendor="Google Inc.",
    platform="Win32",
    webgl_vendor="Intel Inc.",
    renderer="Intel Iris OpenGL Engine",
    fix_hairline=True,
)
driver.get("https://browserleaks.com/webrtc")
driver.sleep(10)
driver.quit()

selenium-stealth also integrates with SeleniumBase BaseCase formats:

Use Syntax Format 2 to override the setUp() method so that selenium-stealth settings are used:

from seleniumbase import BaseCase
from selenium_stealth import stealth

class BaseTestCase(BaseCase):
    def setUp(self):
        super().setUp()
        stealth(self.driver,
            languages=["en-US", "en"],
            vendor="Google Inc.",
            platform="Win32",
            webgl_vendor="Intel Inc.",
            renderer="Intel Iris OpenGL Engine",
            fix_hairline=True,
        )

Then have your test classes inherit BaseTestCase instead of BaseCase.
(See SeleniumBase/help_docs/syntax_formats.md#sb_sf_02 for details.)

To activate UC Mode in BaseCase formats, use --uc as a pytest command-line option:

pytest --uc

For general information about selenium-stealth, see:


For general information about UC Mode, see #2213

@mdmintz mdmintz added documentation UC Mode Undetected Chromedriver Mode (--uc) labels Dec 31, 2023
@mdmintz mdmintz self-assigned this Dec 31, 2023
@AlexPaiva
Copy link

Stealth hasn't been updated in a while, is it still viable?

@mdmintz
Copy link
Member Author

mdmintz commented Jan 3, 2024

@AlexPaiva Some people are still using it, so it's probably still valid, even though it hasn't been updated in awhile.

But at this point, selenium-stealth is mainly just for fingerprint-masking.
The part with avoiding selenium-detection is fully being done by seleniumbase UC Mode.

@xipeng5

This comment was marked as off-topic.

@xipeng5

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation UC Mode Undetected Chromedriver Mode (--uc)
Projects
None yet
Development

No branches or pull requests

3 participants