Class: Puppeteer::Launcher::Chrome::DefaultArgs

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/puppeteer/launcher/chrome.rb

Instance Method Summary collapse

Constructor Details

#initialize(chrome_arg_options) ⇒ DefaultArgs

Returns a new instance of DefaultArgs.

Parameters:



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/puppeteer/launcher/chrome.rb', line 116

def initialize(chrome_arg_options)
  # See https://github.com/GoogleChrome/chrome-launcher/blob/main/docs/chrome-flags-for-tools.md
  chrome_arguments = [
    '--allow-pre-commit-input',
    '--disable-background-networking',
    '--disable-background-timer-throttling',
    '--disable-backgrounding-occluded-windows',
    '--disable-breakpad',
    '--disable-client-side-phishing-detection',
    '--disable-component-extensions-with-background-pages',
    '--disable-component-update',
    '--disable-default-apps',
    '--disable-dev-shm-usage',
    '--disable-extensions',
    # AcceptCHFrame disabled because of crbug.com/1348106.
    '--disable-features=Translate,BackForwardCache,AcceptCHFrame,MediaRouter,OptimizationHints',
    '--disable-hang-monitor',
    '--disable-ipc-flooding-protection',
    '--disable-popup-blocking',
    '--disable-prompt-on-repost',
    '--disable-renderer-backgrounding',
    '--disable-sync',
    '--enable-automation',
    # TODO(sadym): remove '--enable-blink-features=IdleDetection' once
    # IdleDetection is turned on by default.
    '--enable-blink-features=IdleDetection',
    '--enable-features=NetworkServiceInProcess2',
    '--export-tagged-pdf',
    '--force-color-profile=srgb',
    '--metrics-recording-only',
    '--no-first-run',
    '--password-store=basic',
    '--use-mock-keychain',
  ]

  if chrome_arg_options.user_data_dir
    chrome_arguments << "--user-data-dir=#{chrome_arg_options.user_data_dir}"
  end

  if chrome_arg_options.devtools?
    chrome_arguments << '--auto-open-devtools-for-tabs'
  end

  if chrome_arg_options.headless?
    chrome_arguments.concat([
      '--headless',
      '--hide-scrollbars',
      '--mute-audio',
    ])
  end

  # helper for Docker
  # https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#setting-up-chrome-linux-sandbox
  if %w[1 true].include?(ENV['PUPPETEER_RUBY_NO_SANDBOX'])
    ['--no-sandbox', '--disable-setuid-sandbox'].each do |arg|
      unless chrome_arguments.include?(arg)
        chrome_arguments << arg
      end
    end
  end

  if chrome_arg_options.args.all? { |arg| arg.start_with?('-') }
    chrome_arguments << 'about:blank'
  end

  chrome_arguments.concat(chrome_arg_options.args)

  @chrome_arguments = chrome_arguments
end

Instance Method Details

#each(&block) ⇒ Object



186
187
188
189
190
# File 'lib/puppeteer/launcher/chrome.rb', line 186

def each(&block)
  @chrome_arguments.each do |opt|
    block.call(opt)
  end
end