From 7831a8fb447589404e71c564766f90a42b45a360 Mon Sep 17 00:00:00 2001 From: Hugo Slepicka Date: Wed, 23 Mar 2022 17:56:49 -0700 Subject: [PATCH] FIX: Add --no-sandbox if running Chrome and Edge as root. --- botcity/web/browsers/chrome.py | 8 ++++++++ botcity/web/browsers/edge.py | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/botcity/web/browsers/chrome.py b/botcity/web/browsers/chrome.py index bd93a6c..4aa1314 100644 --- a/botcity/web/browsers/chrome.py +++ b/botcity/web/browsers/chrome.py @@ -54,6 +54,14 @@ def default_options(headless=False, download_folder_path=None, user_data_dir=Non chrome_options.add_argument("--hide-scrollbars") chrome_options.add_argument("--mute-audio") + # Check if user is root + try: + # This is only valid with Unix + if os.geteuid() == 0: + chrome_options.add_argument("--no-sandbox") + except AttributeError: + pass + if not user_data_dir: temp_dir = tempfile.TemporaryDirectory(prefix="botcity_") user_data_dir = temp_dir.name diff --git a/botcity/web/browsers/edge.py b/botcity/web/browsers/edge.py index 965ff20..075653b 100644 --- a/botcity/web/browsers/edge.py +++ b/botcity/web/browsers/edge.py @@ -51,6 +51,14 @@ def default_options(headless=False, download_folder_path=None, user_data_dir=Non edge_options.add_argument("--hide-scrollbars") edge_options.add_argument("--mute-audio") + # Check if user is root + try: + # This is only valid with Unix + if os.geteuid() == 0: + edge_options.add_argument("--no-sandbox") + except AttributeError: + pass + if not user_data_dir: temp_dir = tempfile.TemporaryDirectory(prefix="botcity_") user_data_dir = temp_dir.name