Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/docquery/web.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import platform
from io import BytesIO
from pathlib import Path

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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