Skip to content
Merged
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
14 changes: 14 additions & 0 deletions botcity/web/bot.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import annotations

import atexit
import base64
import functools
import glob
Expand Down Expand Up @@ -27,6 +30,7 @@
from selenium.webdriver.support.wait import WebDriverWait, TimeoutException, NoSuchElementException
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.print_page_options import PrintOptions
from weakref import ReferenceType, ref

from . import config, cv2find, compat
from .browsers import BROWSER_CONFIGS, Browser, PageLoadStrategy
Expand All @@ -41,6 +45,14 @@
logger = logging.getLogger(__name__)


def _cleanup(bot: ReferenceType[WebBot]):
if bot() is not None:
try:
bot().stop_browser()
except Exception:
pass


class WebBot(BaseBot):
KEYS = Keys
DEFAULT_DIMENSIONS = (1600, 900)
Expand Down Expand Up @@ -80,6 +92,8 @@ def __init__(self, headless=False):

self._download_folder_path = os.getcwd()

atexit.register(_cleanup, ref(self))

def __enter__(self):
pass

Expand Down