1

The below java code works fine in my machine to disable automation extension. How I can write a replica of this code in ruby

Java

   ChromeOptions options = new ChromeOptions();
   options.setExperimentalOption("useAutomationExtension", false);

In Watir Ruby this code doesn't work

Watir::Browser.new(:chrome, :switches => %w[--disable-popup-blocking  --disable-extensions --disable-infobars] )
Apzal Bahin
  • 61
  • 12

3 Answers3

1

You should be able to pass them along with args: See the update of Watir 6.6: http://watir.com/watir-6-6/ In short:

Watir::Browser.new :chrome, options: {args: %w[--disable-popup-blocking  --disable-extensions --disable-infobars]}

This is how I like to start the browser keeping all options variable.

browser_name = ENV['BROWSER'] || 'chrome'
settings = {}
if ENV['DEVICE'] == 'remote'
  settings[:url] = 'http://selenium__standalone-chrome:4444/wd/hub/'
end

if browser_name == 'chrome'
  args = ['--ignore-certificate-errors', '--disable-popup-blocking', '--disable-translate', '--use-fake-device-for-media-stream', '--use-fake-ui-for-media-stream']
  settings[:options] = {args: args}
end

Watir::Browser.new browser_name.to_sym, settings
Gijs P
  • 1,325
  • 12
  • 28
  • I used the code you provided but I am getting the below pop up everytime the scrip open the browser.How I can avoid showing this pop up."Failed to load extension from :C:\users\\AppData\Local\Temp\scoped_dir14148_503\internal.Loading of unpacked extensions is disabled by the administrator". – Apzal Bahin Mar 08 '18 at 05:35
  • settings = {} args = ['--no-sandbox', '--disable-notifications', '--disable-infobars','--disable-extensions','--disable-popup-blocking'] settings[:options] = {args: args} Watir::Browser.new :chrome, settings – Apzal Bahin Mar 08 '18 at 08:13
  • is there any solution? – Apzal Bahin Mar 08 '18 at 17:43
  • This article goes into that problem: https://stackoverflow.com/questions/43571119/loading-of-unpacked-extensions-is-disabled-by-the-administrator?rq=1 To me it seems that your laptop is moderated by somenoe else, causing you not to be allowed to start the browser with these capabilities. – Gijs P Mar 08 '18 at 22:39
  • Thank You.I have tried all possibility.I can only ask the IT team to lookinto the installation of chrome. – Apzal Bahin Mar 09 '18 at 10:03
1

Maybe try passing it as a raw option:

b = Watir::Browser.new :chrome, options: {options: {'useAutomationExtension' => false}}
Justin Ko
  • 46,526
  • 5
  • 91
  • 101
0

I found the root cause which is not allowing the script to run.

I navigated to below path in "regedit" and deleted the "ExtensionInstallBlacklist" folder but this is a temporary solution the registry will be auto created in some time.

Path: “HKEY_CURRENT_USER\Software\Policies\Google\Chrome\ExtensionInstallBlacklist”

Apzal Bahin
  • 61
  • 12