1

Is it possible to detect instances of firefox browsers that are being controlled by Selenium and geckodriver?

Note there is a corresponding answer for chromedriver, but I'd like to know whether this is possible for firefox/geckodriver.

speedplane
  • 15,673
  • 16
  • 86
  • 138
  • The answer to the linked question states yes, it only provides the workaround details for Chromedriver. – JeffC Oct 01 '17 at 01:48
  • The answer is specific to Chromedriver. The `$cdc_` and `$wdc_` method it discusses is an artifact of chromedriver, not of Selenium generally, and does not apply to geckodriver. – speedplane Oct 02 '17 at 17:46
  • No, it's not. The details are specific to Chromedriver but the answer starts general and answers your question, which is also general. Your question is, "Can a website detect when you are using selenium with geckodriver?" The answer is yes, `Basically the way the selenium detection works, is that they test for pre-defined javascript variables which appear when running with selenium.` and `Of course, all of this depends on which browser you are on. All the different browsers expose different things.` – JeffC Oct 02 '17 at 17:59
  • 1
    It is answering a different question but the answer for that question indicates that the answer is yes to all browsers and goes on to detail how that might work for Chrome specifically. Do you not see that? I quoted the relevant parts above. – JeffC Oct 02 '17 at 20:10
  • Hi Jeff, I understand you, but you're being needlessly pedantic and unhelpful. The actual answer below is helpful. – speedplane Oct 02 '17 at 20:19

2 Answers2

0

Yes you can detect geckodriver controlled selenium with a simple check in JavaScript

var runningSelenium = !("showModalDialog" in window);
Tarun Lalwani
  • 142,312
  • 9
  • 204
  • 265
  • 2
    This doesn't seem accurate. I get a true value when using selenium with geckodriver, but also get true values for Firefox and Chrome on all platforms running normally, as well as Edge on Windows. The only browsers that return false are Safari and Internet Explorer as far as I can see. – bawkstoo Dec 28 '17 at 21:55
  • I had tested this on Mac, so not sure if it is platform specific – Tarun Lalwani Dec 29 '17 at 04:26
0

As others have pointed out, there are a variety of different ways that a site can fingerprint and detect that you are running a browser that has been automated by selenium. Luckily though, some of the detection mechanisms are remarkably simple and just look for a bunch of environmental defaults, such as the screen size etc.

For example, when using Selenium for testing the app OAUTH sign-up sequences for Dropbox etc, the CAPTCHA stage can be avoided by just setting the screen to a non-default value (and offsetting the browser window to simulate a taskbar):

@@headless = Headless.new( dimensions: '1600x1200x24' )
@@headless.start
browser = Watir::Browser.new :firefox
width = browser.execute_script( 'return screen.width;' )
height = browser.execute_script( 'return screen.height;' ) - 95
browser.driver.manage.window.resize_to( width, height )
browser.driver.manage.window.move_to( 0,0 ) 
Buffoonism
  • 1,669
  • 11
  • 11