Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could you put delete_botright_temp_dirs method into try_catch statements? #86

Open
201411164 opened this issue Mar 25, 2024 · 1 comment
Labels
enhancement New feature or request question Further information is requested

Comments

@201411164
Copy link

Hi, I think your Botright is awesome.
But it could be more awesome if you could put
self.delete_botright_temp_dirs()
into try except statements. Because I used to open like 10 multiple Botright at the same time. And the first 10 opens well but
when they are restarting, this part is making an exception. Could you please fix this?

async def ainit(
self,
headless: Optional[bool] = False,
block_images: Optional[bool] = False,
cache_responses: Optional[bool] = False,
user_action_layer: Optional[bool] = False,
scroll_into_view: Optional[bool] = True,
spoof_canvas: Optional[bool] = True,
mask_fingerprint: Optional[bool] = True,
use_undetected_playwright: Optional[bool] = False,
) -> None:
"""
Initialize a Botright instance with specified configurations.

    Args:
        headless (bool, optional): Whether to run the browser in headless mode. Defaults to False.
        block_images (bool, optional): Whether to block images in the browser. Defaults to False.
        cache_responses (bool, optional): Whether to cache HTTP responses. Defaults to False.
        user_action_layer (bool, optional): Whether to enable user action simulation layer. Defaults to False.
        scroll_into_view (bool, optional): Whether to scroll elements into view automatically. Defaults to True.
        spoof_canvas (bool, optional): Whether to disable canvas fingerprinting protection. Defaults to True.
        mask_fingerprint (bool, optional): Whether to mask the browser fingerprint. Defaults to True.
        use_undetected_playwright (bool, optional): Whether to use undetected_playwright . EXPERIMENTAL (TEMP). Defaults to False.
    """

    # Init local-side of the ModelHub
    solver.install(upgrade=True)
    # Starting Playwright
    if use_undetected_playwright:
        # (TODO: TEMP)
        self.playwright: Playwright = await undetected_async_playwright().start()  # type: ignore
    else:
        self.playwright = await async_playwright().start()

    # Getting Chromium based browser engine and deleting botright temp dirs
    self.browser = self.get_browser_engine()
    try:
        self.delete_botright_temp_dirs()
    except Exception as e:
        print(e)
    # Setting Values
    self.headless = headless
    self.block_images = block_images
    self.cache_responses = cache_responses
    self.scroll_into_view = scroll_into_view
    self.user_action_layer = user_action_layer
    self.mask_fingerprint = mask_fingerprint
    self.use_undetected_playwright = use_undetected_playwright
    self.cache: Dict[str, APIResponse] = {}

    # '--disable-gpu', '--incognito', '--disable-blink-features=AutomationControlled'
    # fmt: off
    self.flags = ['--incognito', '--accept-lang=en-US', '--lang=en-US', '--no-pings', '--mute-audio', '--no-first-run', '--no-default-browser-check', '--disable-cloud-import',
                  '--disable-gesture-typing', '--disable-offer-store-unmasked-wallet-cards', '--disable-offer-upload-credit-cards', '--disable-print-preview', '--disable-voice-input',
                  '--disable-wake-on-wifi', '--disable-cookie-encryption', '--ignore-gpu-blocklist', '--enable-async-dns', '--enable-simple-cache-backend', '--enable-tcp-fast-open',
                  '--prerender-from-omnibox=disabled', '--enable-web-bluetooth', '--disable-features=AudioServiceOutOfProcess,IsolateOrigins,site-per-process,TranslateUI,BlinkGenPropertyTrees',
                  '--aggressive-cache-discard', '--disable-extensions', '--disable-ipc-flooding-protection', '--disable-blink-features=AutomationControlled', '--test-type',
                  '--enable-features=NetworkService,NetworkServiceInProcess,TrustTokens,TrustTokensAlwaysAllowIssuance', '--disable-component-extensions-with-background-pages',
                  '--disable-default-apps', '--disable-breakpad', '--disable-component-update', '--disable-domain-reliability', '--disable-sync', '--disable-client-side-phishing-detection',
                  '--disable-hang-monitor', '--disable-popup-blocking', '--disable-prompt-on-repost', '--metrics-recording-only', '--safebrowsing-disable-auto-update', '--password-store=basic',
                  '--autoplay-policy=no-user-gesture-required', '--use-mock-keychain', '--force-webrtc-ip-handling-policy=disable_non_proxied_udp',
                  '--webrtc-ip-handling-policy=disable_non_proxied_udp', '--disable-session-crashed-bubble', '--disable-crash-reporter', '--disable-dev-shm-usage', '--force-color-profile=srgb',
                  '--disable-translate', '--disable-background-networking', '--disable-background-timer-throttling', '--disable-backgrounding-occluded-windows', '--disable-infobars',
                  '--hide-scrollbars', '--disable-renderer-backgrounding', '--font-render-hinting=none', '--disable-logging', '--enable-surface-synchronization',
                  '--run-all-compositor-stages-before-draw', '--disable-threaded-animation', '--disable-threaded-scrolling', '--disable-checker-imaging',
                  '--disable-new-content-rendering-timeout', '--disable-image-animation-resync', '--disable-partial-raster', '--blink-settings=primaryHoverType=2,availableHoverTypes=2,'
                  'primaryPointerType=4,availablePointerTypes=4', '--disable-layer-tree-host-memory-pressure']
@201411164 201411164 added enhancement New feature or request question Further information is requested labels Mar 25, 2024
@Vinyzu
Copy link
Owner

Vinyzu commented Mar 25, 2024

This behavior (temp folders for persistent context) will probably be rewritten in the next update, but im not quite sure how the next update will look or when it will come out...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants