mokr.launch =========== .. py:module:: mokr.launch Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/mokr/launch/base/index /autoapi/mokr/launch/chrome/index /autoapi/mokr/launch/firefox/index Classes ------- .. autoapisummary:: mokr.launch.Launcher mokr.launch.ChromeLauncher mokr.launch.FirefoxLauncher Package Contents ---------------- .. py:class:: Launcher(binary_path: str = None, headless: bool = None, user_data_dir: str = None, devtools: bool = False, ignore_default_args: bool | list[str] = False, ignore_https_errors: bool = False, default_viewport: dict[str, int] = None, proxy: str = None, default_user_agent: str = None, slow_mo: int = 0, log_level: str | int = None, args: list[str] = None, dumpio: bool = False, env: dict[str, str] = None, loop: asyncio.AbstractEventLoop = None, firefox_user_prefs: dict = None, firefox_addons_paths: list[str] = None) Bases: :py:obj:`abc.ABC` Class to handle launching browser process and creation of a `mokr.browser.Browser` object. :param binary_path: Path to executable to use. Defaults to None (looks for default executable that can be installed via `mokr install`). :type binary_path: str, optional :param headless: Run the browser in headless (no window) mode. Defaults to None (uses opposite value to `devtools`). :type headless: bool, optional :param user_data_dir: Path to a user data directory. Defaults to None. :type user_data_dir: str, optional :param devtools: Automatically open the developer tools panel. Defaults to False. :type devtools: bool, optional :param ignore_default_args: Either a bool to indicate ignoring all arguments or a list of arguments to ignore. Be cautious, ignoring some arguments may cause unexpected results. Defaults to False. :type ignore_default_args: bool | list[str], optional :param ignore_https_errors: Ignore site security errors. Defaults to False. :type ignore_https_errors: bool, optional :param default_viewport: Set the default viewport for new pages. Accepts a dictionary keyed with viewport options. Not all viewport options are considered, only: "isMobile", "width", "height", "deviceScaleFactor", "isLandscape", and "hasTouch". Defaults to None (800x600 viewport). :type default_viewport: dict[str, int], optional :param proxy: Proxy to route all requests through. Can be a regular HTTP/S proxy or SOCKS proxy. Expects proxy as `://[(optional):]@`. :type proxy: str, optional :param default_user_agent: Default user agent to use on all new pages. :type default_user_agent: str, optional :param slow_mo: Slow execution of remote calls by the given time in milliseconds. Defaults to 0. :type slow_mo: int, optional :param log_level: Log level to log at. Defaults to None (same as root). :type log_level: str | int, optional :param args: Additional arguments to pass to the browser process when launching. Defaults to None. :type args: list[str], optional :param dumpio: Pipe the browser process' stdout and stderr into ``process.stdout`` and ``process.stderr``. Defaults to False. :type dumpio: bool, optional :param env: Additional environment variables that the browser process will be able to read. Defaults to None. :type env: dict[str, str], optional :param loop: A running asyncio loop to execute within. Defaults to None (uses `asyncio.get_event_loop`). :type loop: asyncio.AbstractEventLoop, optional :param firefox_user_prefs: Firefox only. User preferences to load. :type firefox_user_prefs: dict :param firefox_addons_paths: Firefox only. A list of paths to addons that will be installed as temporary extensions. :type firefox_addons_paths: list[str] Example:: ```python from mokr.launch import ChromeLauncher, FirefoxLauncher async with ChromeLauncher() as browser: page = await browser.first_page() await page.goto("https://example.com") # Or, to avoid the contextmanager. launcher = FirefoxLauncher() browser = await launcher.launch() page = await browser.first_page() await page.goto("https://example.com") await launcher.stop() ``` .. py:attribute:: kind :value: 'abstract' .. py:attribute:: port .. py:attribute:: url .. py:attribute:: dumpio :value: False .. py:attribute:: env :value: None .. py:attribute:: ignore_https_errors :value: False .. py:attribute:: default_viewport .. py:attribute:: default_user_agent :value: None .. py:attribute:: slow_mo :value: 0 .. py:attribute:: firefox_user_prefs :value: None .. py:attribute:: firefox_addons_paths :value: None .. py:attribute:: browser_closed :value: True .. py:attribute:: browser_arguments :type: list[str] :value: [] .. py:attribute:: browser_binary :value: None .. py:attribute:: cmd .. py:attribute:: initial_page_promise .. py:method:: stop() -> None :async: Stop the browser process if it is running. .. py:method:: launch() -> mokr.browser.browser.Browser :async: Start browser process and return a `mokr.browser.Browser` object. .. py:method:: ensure_initial_page(browser: mokr.browser.browser.Browser) -> None :async: Wait for a new page in a given `browser` to be created. :param browser: Target `mokr.browser.Browser`. :type browser: Browser .. py:method:: kill_browser() -> None :async: Kill running browser process. .. py:class:: ChromeLauncher(binary_path: str = None, headless: bool = None, user_data_dir: str = None, devtools: bool = False, ignore_default_args: bool | list[str] = False, ignore_https_errors: bool = False, default_viewport: dict[str, int] = None, proxy: str = None, default_user_agent: str = None, slow_mo: int = 0, log_level: str | int = None, args: list[str] = None, dumpio: bool = False, env: dict[str, str] = None, loop: asyncio.AbstractEventLoop = None, firefox_user_prefs: dict = None, firefox_addons_paths: list[str] = None) Bases: :py:obj:`mokr.launch.base.Launcher` Class to handle launching browser process and creation of a `mokr.browser.Browser` object. :param binary_path: Path to executable to use. Defaults to None (looks for default executable that can be installed via `mokr install`). :type binary_path: str, optional :param headless: Run the browser in headless (no window) mode. Defaults to None (uses opposite value to `devtools`). :type headless: bool, optional :param user_data_dir: Path to a user data directory. Defaults to None. :type user_data_dir: str, optional :param devtools: Automatically open the developer tools panel. Defaults to False. :type devtools: bool, optional :param ignore_default_args: Either a bool to indicate ignoring all arguments or a list of arguments to ignore. Be cautious, ignoring some arguments may cause unexpected results. Defaults to False. :type ignore_default_args: bool | list[str], optional :param ignore_https_errors: Ignore site security errors. Defaults to False. :type ignore_https_errors: bool, optional :param default_viewport: Set the default viewport for new pages. Accepts a dictionary keyed with viewport options. Not all viewport options are considered, only: "isMobile", "width", "height", "deviceScaleFactor", "isLandscape", and "hasTouch". Defaults to None (800x600 viewport). :type default_viewport: dict[str, int], optional :param proxy: Proxy to route all requests through. Can be a regular HTTP/S proxy or SOCKS proxy. Expects proxy as `://[(optional):]@`. :type proxy: str, optional :param default_user_agent: Default user agent to use on all new pages. :type default_user_agent: str, optional :param slow_mo: Slow execution of remote calls by the given time in milliseconds. Defaults to 0. :type slow_mo: int, optional :param log_level: Log level to log at. Defaults to None (same as root). :type log_level: str | int, optional :param args: Additional arguments to pass to the browser process when launching. Defaults to None. :type args: list[str], optional :param dumpio: Pipe the browser process' stdout and stderr into ``process.stdout`` and ``process.stderr``. Defaults to False. :type dumpio: bool, optional :param env: Additional environment variables that the browser process will be able to read. Defaults to None. :type env: dict[str, str], optional :param loop: A running asyncio loop to execute within. Defaults to None (uses `asyncio.get_event_loop`). :type loop: asyncio.AbstractEventLoop, optional :param firefox_user_prefs: Firefox only. User preferences to load. :type firefox_user_prefs: dict :param firefox_addons_paths: Firefox only. A list of paths to addons that will be installed as temporary extensions. :type firefox_addons_paths: list[str] Example:: ```python from mokr.launch import ChromeLauncher, FirefoxLauncher async with ChromeLauncher() as browser: page = await browser.first_page() await page.goto("https://example.com") # Or, to avoid the contextmanager. launcher = FirefoxLauncher() browser = await launcher.launch() page = await browser.first_page() await page.goto("https://example.com") await launcher.stop() ``` .. py:attribute:: kind :value: 'chrome' .. py:class:: FirefoxLauncher(*args, **kwargs) Bases: :py:obj:`mokr.launch.base.Launcher` Class to handle launching browser process and creation of a `mokr.browser.Browser` object. :param binary_path: Path to executable to use. Defaults to None (looks for default executable that can be installed via `mokr install`). :type binary_path: str, optional :param headless: Run the browser in headless (no window) mode. Defaults to None (uses opposite value to `devtools`). :type headless: bool, optional :param user_data_dir: Path to a user data directory. Defaults to None. :type user_data_dir: str, optional :param devtools: Automatically open the developer tools panel. Defaults to False. :type devtools: bool, optional :param ignore_default_args: Either a bool to indicate ignoring all arguments or a list of arguments to ignore. Be cautious, ignoring some arguments may cause unexpected results. Defaults to False. :type ignore_default_args: bool | list[str], optional :param ignore_https_errors: Ignore site security errors. Defaults to False. :type ignore_https_errors: bool, optional :param default_viewport: Set the default viewport for new pages. Accepts a dictionary keyed with viewport options. Not all viewport options are considered, only: "isMobile", "width", "height", "deviceScaleFactor", "isLandscape", and "hasTouch". Defaults to None (800x600 viewport). :type default_viewport: dict[str, int], optional :param proxy: Proxy to route all requests through. Can be a regular HTTP/S proxy or SOCKS proxy. Expects proxy as `://[(optional):]@`. :type proxy: str, optional :param default_user_agent: Default user agent to use on all new pages. :type default_user_agent: str, optional :param slow_mo: Slow execution of remote calls by the given time in milliseconds. Defaults to 0. :type slow_mo: int, optional :param log_level: Log level to log at. Defaults to None (same as root). :type log_level: str | int, optional :param args: Additional arguments to pass to the browser process when launching. Defaults to None. :type args: list[str], optional :param dumpio: Pipe the browser process' stdout and stderr into ``process.stdout`` and ``process.stderr``. Defaults to False. :type dumpio: bool, optional :param env: Additional environment variables that the browser process will be able to read. Defaults to None. :type env: dict[str, str], optional :param loop: A running asyncio loop to execute within. Defaults to None (uses `asyncio.get_event_loop`). :type loop: asyncio.AbstractEventLoop, optional :param firefox_user_prefs: Firefox only. User preferences to load. :type firefox_user_prefs: dict :param firefox_addons_paths: Firefox only. A list of paths to addons that will be installed as temporary extensions. :type firefox_addons_paths: list[str] Example:: ```python from mokr.launch import ChromeLauncher, FirefoxLauncher async with ChromeLauncher() as browser: page = await browser.first_page() await page.goto("https://example.com") # Or, to avoid the contextmanager. launcher = FirefoxLauncher() browser = await launcher.launch() page = await browser.first_page() await page.goto("https://example.com") await launcher.stop() ``` .. py:attribute:: kind :value: 'firefox' .. py:method:: launch() -> mokr.browser.browser.Browser :async: Start browser process and return a `mokr.browser.Browser` object.