MCPcopy Create free account
hub / github.com/Vinyzu/Botright / new_browser

Function new_browser

botright/playwright_mock/browser.py:31–115  ·  view source on GitHub ↗

Create a new browser context with custom configurations. Args: botright (Botright): The Botright Instance from the main thread. proxy (ProxyManager): An instance of ProxyManager for configuring proxy settings. faker (Faker): An instance of Faker for generating fake

(botright: Botright, proxy: ProxyManager, faker: Faker, flags: List[str], **launch_arguments)

Source from the content-addressed store, hash-verified

29
30
31async def new_browser(botright: Botright, proxy: ProxyManager, faker: Faker, flags: List[str], **launch_arguments) -> BrowserContext:
32 """
33 Create a new browser context with custom configurations.
34
35 Args:
36 botright (Botright): The Botright Instance from the main thread.
37 proxy (ProxyManager): An instance of ProxyManager for configuring proxy settings.
38 faker (Faker): An instance of Faker for generating fake user agent and other details.
39 flags (List[str]): The command line flags to pass into the Browser Instance.
40 # browser_path (str): The path to the real browser executable.
41 # headless (bool, optional): Whether to run the browser in headless mode. Defaults to False.
42 # mask_fingerprint (bool, optional): Whether to mask the browser fingerprint. Defaults to True.
43 # user_action_layer (bool, optional): Whether to enable user action simulation layer. Defaults to False.
44 # scroll_into_view (bool, optional): Whether to scroll elements into view automatically. Defaults to True.
45 **launch_arguments: Additional launch arguments for configuring the browser context. See https://playwright.dev/python/docs/api/class-browser#browser-new-context.
46
47 Returns:
48 BrowserContext: A new browser context with the specified configurations.
49 """
50 if botright.mask_fingerprint:
51 fingerprint = faker.fingerprint
52 parsed_launch_arguments = {
53 "locale": "en-US",
54 "user_agent": fingerprint.navigator.user_agent,
55 "timezone_id": proxy.timezone,
56 "geolocation": {"longitude": proxy.longitude, "latitude": proxy.latitude, "accuracy": 0.7},
57 "permissions": ["geolocation"],
58 "ignore_https_errors": True,
59 "screen": {"width": fingerprint.screen.width, "height": fingerprint.screen.height},
60 "viewport": {"width": fingerprint.screen.avail_width, "height": fingerprint.screen.avail_height},
61 "color_scheme": "dark",
62 "proxy": proxy.browser_proxy,
63 "http_credentials": {"username": proxy.username, "password": proxy.password} if proxy.username else None,
64 "ignore_default_args": ["--enable-automation"],
65 **launch_arguments,
66 } # self.faker.locale
67 else:
68 parsed_launch_arguments = {
69 "locale": "en-US",
70 "timezone_id": proxy.timezone,
71 "geolocation": {"longitude": proxy.longitude, "latitude": proxy.latitude, "accuracy": 0.7},
72 "ignore_https_errors": True,
73 "color_scheme": "dark",
74 "proxy": proxy.browser_proxy,
75 "http_credentials": {"username": proxy.username, "password": proxy.password} if proxy.username else None,
76 "ignore_default_args": ["--enable-automation"],
77 **launch_arguments,
78 } # self.faker.locale
79
80 if sys.version_info.minor >= 10:
81 temp_dir = TemporaryDirectory(prefix="botright-", ignore_cleanup_errors=True)
82 else:
83 temp_dir = TemporaryDirectory(prefix="botright-")
84 temp_dir_path = temp_dir.name
85 botright.temp_dirs.append(temp_dir)
86
87 # Spawning a new Context for more options
88 if proxy.browser_proxy:

Callers

nothing calls this directly

Calls 3

block_imagesMethod · 0.95
cache_responsesMethod · 0.95
BrowserContextClass · 0.85

Tested by

no test coverage detected