{"id":9279,"library":"robocorp-browser","title":"Robocorp Browser","description":"The `robocorp-browser` package is a Python library for browser automation, acting as a lightweight wrapper around the Playwright project. It provides quality-of-life improvements, such as automatic lifecycle management for Playwright objects, and is primarily designed to be used within the Robocorp automation framework, especially with `robocorp-tasks`. The current version is 2.4.0. It is actively maintained as part of the broader Robocorp ecosystem.","status":"active","version":"2.4.0","language":"en","source_language":"en","source_url":"https://github.com/robocorp/robocorp","tags":["browser automation","RPA","Playwright","Robocorp","web scraping"],"install":[{"cmd":"pip install robocorp-browser","lang":"bash","label":"Install `robocorp-browser`"}],"dependencies":[{"reason":"Robocorp Browser is a wrapper around Playwright. It handles Playwright browser installation automatically by default, but Playwright itself is the underlying engine.","package":"playwright","optional":false},{"reason":"Commonly used in conjunction with robocorp-browser for defining and orchestrating automation tasks within the Robocorp platform.","package":"robocorp-tasks","optional":true},{"reason":"Often used for securely managing credentials and secrets in browser automation scripts.","package":"robocorp-vault","optional":true}],"imports":[{"symbol":"browser","correct":"from robocorp import browser"},{"note":"For defining automation tasks, typically used with robocorp-browser.","symbol":"task","correct":"from robocorp.tasks import task"},{"note":"For accessing secrets, commonly used with robocorp-browser automation for logins.","symbol":"vault","correct":"from robocorp import vault"}],"quickstart":{"code":"import os\nfrom robocorp import browser\nfrom robocorp.tasks import task\nfrom robocorp import vault # For secret management example\n\n@task\ndef automate_browser_example():\n    \"\"\"Start a browser, navigate, and interact with a page.\"\"\"\n    # Configure browser settings (optional)\n    browser.configure(\n        browser_engine=\"chromium\",\n        headless=True, # Set to False to see the browser UI\n        slowmo=100, # Run interactions in slow motion (milliseconds)\n        screenshot=\"only-on-failure\", # Capture screenshot on error\n    )\n\n    # Get a secret (example: login credentials)\n    # In a real scenario, configure 'default-account' in Robocorp Vault\n    # For quickstart, we use environment variables as a fallback\n    username = os.environ.get('TEST_USERNAME', 'user')\n    password = os.environ.get('TEST_PASSWORD', 'pass')\n    \n    try:\n        account = vault.get_secret(\"default-account\")\n        username = account[\"username\"]\n        password = account[\"password\"]\n    except Exception:\n        print(\"Warning: Could not get secret 'default-account'. Using environment variables or defaults.\")\n\n    # Navigate to a page (this will automatically launch the browser if not already open)\n    page = browser.goto(\"https://www.example.com/login\") # Replace with a real login page\n\n    # Interact with elements using Playwright API\n    # Example: fill login form (replace with actual selectors)\n    # page.fill(\"#username_field\", username)\n    # page.fill(\"#password_field\", password)\n    # page.click(\"#login_button\")\n\n    # Perform some action, e.g., take a screenshot\n    browser.screenshot(page=page, path=\"output/example_screenshot.png\")\n    print(f\"Navigated to {page.url} and took a screenshot.\")\n\n    # The browser instance is automatically closed when the task finishes.\n","lang":"python","description":"This quickstart demonstrates how to initialize the browser, configure its behavior (like headless mode and slow motion), navigate to a URL, and interact with elements using the underlying Playwright API. It also shows how to integrate with `robocorp-tasks` and `robocorp-vault` for defining tasks and managing secrets."},"warnings":[{"fix":"Explicitly set `headless=True` to ensure headless execution or `headless=False` to ensure UI is always shown, regardless of the environment detection.","message":"The default behavior of the `headless` option in `browser.configure` changed in version 2.0.0. If `headless` is unset or set to `None`, the browser UI will now be shown (i.e., `headless=False`) unless running in a Linux VM without a `DISPLAY` or `WAYLAND_DISPLAY` environment variable set.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"After configuring `persistent_context_directory`, interact with the browser using `browser.page()` or `browser.context()` directly, which implicitly handle the browser instance creation with the persistent context.","message":"When using `persistent_context_directory` in `browser.configure` (introduced in 2.2.0), calling `browser.browser()` directly will raise a `RuntimeError`. This is because the persistent context requires the browser and context to be created together.","severity":"gotcha","affected_versions":">=2.2.0"},{"fix":"Add `robocorp-browser` to your project's dependency management file (e.g., `pip install robocorp-browser` locally, or add to `requirements.txt` / `conda.yaml` for Robocorp environments).","message":"`robocorp-browser` is not included in the `robocorp` metapackage. If you are using `robocorp-tasks` or other Robocorp tools, you must explicitly declare `robocorp-browser` as a dependency in your project's `conda.yaml`, `package.yaml`, `requirements.txt`, or similar configuration file.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Run `playwright install` in your environment to ensure the necessary browser binaries are downloaded. Alternatively, configure `browser.configure(install=True)` which attempts to download if the browser fails to launch. Ensure your system meets Playwright's requirements.","cause":"The underlying Playwright browser executable is not installed or cannot be found, or there's an incompatibility with the system environment.","error":"BrowserNotFoundError: Failed to start a browser: - chromium: Could not get browser version."},{"fix":"Instead of `browser.browser()`, use `browser.page()` or `browser.context()` after calling `browser.configure(persistent_context_directory='...')`. These methods correctly manage the browser and context with the persistent directory.","cause":"You are attempting to call `browser.browser()` while `persistent_context_directory` has been set in `browser.configure()`. The `browser.browser()` method is incompatible with persistent contexts.","error":"RuntimeError: If persistent_context_directory is specified in the configuration and this method is called a RuntimeError is raised (as in this case this API is not applicable as the browser and the context must be created at once and the browser can't be reused for the session)."},{"fix":"Ensure your Windows system's code page is set to Unicode (e.g., UTF-8). This can often be resolved by changing system locale settings or running scripts with `chcp 65001` (though robust solutions involve proper encoding handling within Python or environment configuration).","cause":"This typically occurs on Windows systems when the default console code page is not set to a Unicode-compatible encoding, leading to issues with non-ASCII characters in logs or outputs.","error":"UnicodeEncodeError: 'charmap' codec can't encode character '\\u2013' in position ..."}]}