Can Websites Detect When You're Using Selenium with ChromeDriver

By FoxLearn 12/9/2024 8:39:33 AM   46
Selenium detection works by testing for specific JavaScript variables that appear when running with Selenium.

Bot detection scripts typically look for variables containing the words "selenium" or "webdriver" in the window object, as well as document variables like $cdc_ and $wdc_. The specific variables and detection methods may vary depending on the browser being used, as different browsers expose different information.

You can use Vim or Perl to replace the cdc_ string in ChromeDriver to help avoid detection by bot scripts that look for this variable.

Before editing ChromeDriver, make sure to create a copy of the original. The goal is to modify the cdc_ string (e.g., $cdc_lasutopfhvcZLmcfl) to avoid detection by bot scripts.

For example, Using Vim

vim -b /path/to/chromedriver

After opening ChromeDriver in Vim, you'll likely see a lot of gibberish.

To modify the cdc_ string, use the command :%s/cdc_/dog_/g (replacing dog_ with any string of the same length as cdc_). After making the change, save and quit with :wq!, or quit without saving using :q!. The -b option ensures Vim opens the file as binary, preventing issues with line endings.

For examle, Using Perl

perl -pi -e 's/cdc_/dog_/g' /path/to/chromedriver

Ensure the replacement string (e.g., dog_) has the same number of characters as the original string (e.g., cdc_), or else ChromeDriver may fail to function properly.

To verify all occurrences of cdc_ were replaced, you can search for it again in the file to ensure no instances remain.

grep "cdc_" /path/to/chromedriver

If no output is returned after replacing cdc_, the replacement was successful. To verify, double-click the altered ChromeDriver; a terminal window should open. If "killed" doesn't appear in the output, the alteration worked. Ensure the modified ChromeDriver is named "chromedriver," and the original binary is either moved or renamed.