<commit_before>require 'capybara'
require 'selenium/webdriver'

module Capybara

  module_function

  def register_chrome_driver(name, window_width: 1280, window_height: 1600)
    Capybara.register_driver name do |app|
      options = ::Selenium::WebDriver::Chrome::Options.new

      options.add_preference(:download, prompt_for_download: false,
                             default_directory: File.join(Dir.pwd, 'tmp', 'screenshots'))

      options.add_preference(:browser, set_download_behavior: {behavior: 'allow'})
      options.add_argument('--headless')
      options.add_argument('--disable-gpu')
      options.add_argument("--window-size=#{window_width},#{window_height}")

      driver = ::Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)

      ### Allow file downloads in Google Chrome when headless!!!
      ### https://bugs.chromium.org/p/chromium/issues/detail?id=696481#c89
      bridge = driver.browser.send(:bridge)

      path = '/session/:session_id/chromium/send_command'
      path[':session_id'] = bridge.session_id

      bridge.http.call(:post, path, cmd: 'Page.setDownloadBehavior',
                       params: {
                           behavior: 'allow',
                           downloadPath: File.join(Dir.pwd, 'tmp', 'downloads')
                       })
      ###

      driver
    end
  end
end<commit_msg>Add no-sanbox and disable-extensions option for work from docker container<commit_after>require 'capybara'
require 'selenium/webdriver'

module Capybara

  module_function

  def register_chrome_driver(name, window_width: 1280, window_height: 1600)
    Capybara.register_driver name do |app|
      options = ::Selenium::WebDriver::Chrome::Options.new

      options.add_preference(:download, prompt_for_download: false,
                             default_directory: File.join(Dir.pwd, 'tmp', 'screenshots'))

      options.add_preference(:browser, set_download_behavior: {behavior: 'allow'})
      options.add_argument('--headless')
      options.add_argument('--disable-gpu')
      options.add_argument('--disable-extensions')
      options.add_argument("--no-sandbox")
      options.add_argument("--window-size=#{window_width},#{window_height}")

      driver = ::Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)

      ### Allow file downloads in Google Chrome when headless!!!
      ### https://bugs.chromium.org/p/chromium/issues/detail?id=696481#c89
      bridge = driver.browser.send(:bridge)

      path = '/session/:session_id/chromium/send_command'
      path[':session_id'] = bridge.session_id

      bridge.http.call(:post, path, cmd: 'Page.setDownloadBehavior',
                       params: {
                           behavior: 'allow',
                           downloadPath: File.join(Dir.pwd, 'tmp', 'downloads')
                       })
      ###

      driver
    end
  end
end
{'fraction_non_alphanumeric': 0.12840869865377977, 'fraction_numerical': 0.011045909561615464, 'mean_word_length': 2.843501326259947, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3286882', 'n_tokens_mistral': 892, 'n_tokens_neox': 833, 'n_words': 148}