MCPcopy
hub / github.com/ArchiveBox/ArchiveBox / chrome_args

Function chrome_args

archivebox/util.py:221–275  ·  view source on GitHub ↗

helper to build up a chrome shell command with arguments

(**options)

Source from the content-addressed store, hash-verified

219
220@enforce_types
221def chrome_args(**options) -> List[str]:
222 """helper to build up a chrome shell command with arguments"""
223
224 from .config import CHROME_OPTIONS, CHROME_VERSION
225
226 options = {**CHROME_OPTIONS, **options}
227
228 if not options['CHROME_BINARY']:
229 raise Exception('Could not find any CHROME_BINARY installed on your system')
230
231 cmd_args = [options['CHROME_BINARY']]
232
233 if options['CHROME_HEADLESS']:
234 chrome_major_version = int(re.search(r'\s(\d+)\.\d', CHROME_VERSION)[1])
235 if chrome_major_version >= 111:
236 cmd_args += ("--headless=new",)
237 else:
238 cmd_args += ('--headless',)
239
240 if not options['CHROME_SANDBOX']:
241 # assume this means we are running inside a docker container
242 # in docker, GPU support is limited, sandboxing is unecessary,
243 # and SHM is limited to 64MB by default (which is too low to be usable).
244 cmd_args += (
245 "--no-sandbox",
246 "--no-zygote",
247 "--disable-dev-shm-usage",
248 "--disable-software-rasterizer",
249 "--run-all-compositor-stages-before-draw",
250 "--hide-scrollbars",
251 "--window-size=1440,2000",
252 "--autoplay-policy=no-user-gesture-required",
253 "--no-first-run",
254 "--use-fake-ui-for-media-stream",
255 "--use-fake-device-for-media-stream",
256 "--disable-sync",
257 )
258
259
260 if not options['CHECK_SSL_VALIDITY']:
261 cmd_args += ('--disable-web-security', '--ignore-certificate-errors')
262
263 if options['CHROME_USER_AGENT']:
264 cmd_args += ('--user-agent={}'.format(options['CHROME_USER_AGENT']),)
265
266 if options['RESOLUTION']:
267 cmd_args += ('--window-size={}'.format(options['RESOLUTION']),)
268
269 if options['CHROME_TIMEOUT']:
270 cmd_args += ('--timeout={}'.format(options['CHROME_TIMEOUT'] * 1000),)
271
272 if options['CHROME_USER_DATA_DIR']:
273 cmd_args.append('--user-data-dir={}'.format(options['CHROME_USER_DATA_DIR']))
274
275 return cmd_args
276
277def chrome_cleanup():
278 """

Callers 4

save_singlefileFunction · 0.85
save_pdfFunction · 0.85
save_domFunction · 0.85
save_screenshotFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected