From 693b60c85da996d83d65cc67be59e1092e792e0d Mon Sep 17 00:00:00 2001 From: Denini Gabriel Date: Fri, 19 Sep 2025 18:39:48 -0300 Subject: [PATCH] fix: replace os.geteuid() with cross-platform admin check --- src/docquery/web.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/docquery/web.py b/src/docquery/web.py index 82352e3..971fd2c 100644 --- a/src/docquery/web.py +++ b/src/docquery/web.py @@ -1,4 +1,5 @@ import os +import platform from io import BytesIO from pathlib import Path @@ -40,7 +41,7 @@ def _reinit_driver(self): options = Options() options.headless = True options.add_argument("--window-size=1920,1200") - if os.geteuid() == 0: + if is_admin(): options.add_argument("--no-sandbox") self.driver = webdriver.Chrome( @@ -127,3 +128,16 @@ def get_webdriver(): if WEB_DRIVER is None: WEB_DRIVER = WebDriver() return WEB_DRIVER + + +def is_admin(): + """Check if script is running with admin/root privileges""" + try: + if platform.system() == "Windows": + import ctypes + return ctypes.windll.shell32.IsUserAnAdmin() != 0 + else: + # Unix/Linux/macOS + return os.geteuid() == 0 + except: + return False