mokr.launch.base
Attributes
Classes
Class to handle launching browser process and creation of a |
Module Contents
- mokr.launch.base.LOGGER
- class mokr.launch.base.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:
abc.ABCClass to handle launching browser process and creation of a
mokr.browser.Browserobject.- Parameters:
binary_path (str, optional) – Path to executable to use. Defaults to None (looks for default executable that can be installed via
mokr install).headless (bool, optional) – Run the browser in headless (no window) mode. Defaults to None (uses opposite value to
devtools).user_data_dir (str, optional) – Path to a user data directory. Defaults to None.
devtools (bool, optional) – Automatically open the developer tools panel. Defaults to False.
ignore_default_args (bool | list[str], optional) – 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.
ignore_https_errors (bool, optional) – Ignore site security errors. Defaults to False.
default_viewport (dict[str, int], optional) – 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).
proxy (str, optional) – Proxy to route all requests through. Can be a regular HTTP/S proxy or SOCKS proxy. Expects proxy as
<scheme>://[(optional)<username>:<password>]@<host><password>.default_user_agent (str, optional) – Default user agent to use on all new pages.
slow_mo (int, optional) – Slow execution of remote calls by the given time in milliseconds. Defaults to 0.
log_level (str | int, optional) – Log level to log at. Defaults to None (same as root).
args (list[str], optional) – Additional arguments to pass to the browser process when launching. Defaults to None.
dumpio (bool, optional) – Pipe the browser process’ stdout and stderr into
process.stdoutandprocess.stderr. Defaults to False.env (dict[str, str], optional) – Additional environment variables that the browser process will be able to read. Defaults to None.
loop (asyncio.AbstractEventLoop, optional) – A running asyncio loop to execute within. Defaults to None (uses
asyncio.get_event_loop).firefox_user_prefs (dict) – Firefox only. User preferences to load.
firefox_addons_paths (list[str]) – Firefox only. A list of paths to addons that will be installed as temporary extensions.
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() ```- kind = 'abstract'
- port
- url
- dumpio = False
- env = None
- ignore_https_errors = False
- default_viewport
- default_user_agent = None
- slow_mo = 0
- firefox_user_prefs = None
- firefox_addons_paths = None
- browser_closed = True
- browser_arguments: list[str] = []
- browser_binary = None
- cmd
- initial_page_promise
- async stop() None
Stop the browser process if it is running.
- async launch() mokr.browser.browser.Browser
Start browser process and return a
mokr.browser.Browserobject.
- async ensure_initial_page(browser: mokr.browser.browser.Browser) None
Wait for a new page in a given
browserto be created.- Parameters:
browser (Browser) – Target
mokr.browser.Browser.
- async kill_browser() None
Kill running browser process.