DEV Community

Tony Colston
Tony Colston

Posted on

What is the cdc variable in chromedriver?

I saw this thread on reddit and wondered myself WTF is the cdc variable in chromedriver

https://www.reddit.com/r/selenium/comments/cfjydg/selenium_chromdriver_replaced_cdc_variable/

So what is it and why would you even care?

It is a variable that shows up in document when you are using chromedriver. With one tiny subtle thing... if you just run driver.get and do not interact with the page in Selenium the variable does not show up...

Websites that know about it can detect that they are being called/displayed from an automated browser.

You can see it if you look at document["$cdc_asdjflasutopfhvcZLmcfl_"] in javascript. You can verify this by adding this code to a Selenium script in Python.

print(driver.execute_script("return document['$cdc_asdjflasutopfhvcZLmcfl_']"))
Enter fullscreen mode Exit fullscreen mode

This will always return something if you are using chromedriver (or at least as of chromedriver 75).

Where does that variable come from? It is code that is embedded in chromedriver. You can find it yourself in the chromium source code. https://github.com/chromium/chromium/tree/master/chrome/test/chromedriver

What if you want to change it so your Selenium scripts will be undetected? The not so easy way is to compile it yourself (but you get points for being a nerd).

The much easier way is to change that variable is to edit your chromedriver executable. See that link below for a reasonable way to do that. Be aware when you change the executable it will trigger a Win10 virus scan the first time you run it again after you hacked it.

I have used this with vim on Windows 10 and it works.

https://stackoverflow.com/questions/33225947/can-a-website-detect-when-you-are-using-selenium-with-chromedriver

Oldest comments (2)

Collapse
 
allahyar profile image
Allahyar

I changed the cdc_ variables and was detected, I am looking for another solution :)

Collapse
 
mwangishad profile image
shaddyshad

I noticed that in addition to changing the cdc_ variables, some services can still detect your activity based on the interaction time. You can add some sleep time in between interactions.