Skip to main content

A Python library for programmatically controlling and interacting with a web browser using the Chrome DevTools Protocol

Project description

Browsinator

Browsinator is a Python library for programmatically controlling and interacting with a web browser using the Chrome DevTools Protocol.

Installation

To install Browsinator, you'll need Python 3.6 or later. You can install it using pip:

pip install browsinator

Usage

Here's a basic example of how to use Browsinator:

from browsinator import Browser
Browser.start() # Start Chrome or ...
Browser.start_brave() # Start Brave
browser = Browser()

Navigate to a URL

browser.load("https://example.com", wait=True)

Run JavaScript

result = browser.run_script("document.title")
print(f"Page title: {result}")

Monitor network traffic

browser.match_network("api/data", lambda req, res, data: print(f"API data: {data}"))
browser.monitor_network()

Run raw debug methods

For example calling Network.getResponseBody with a specific request ID:

result = browser.send_command("Network.getResponseBody", {"requestId": 1})
print(f"Response body: {result}")

Simulate user input

browser.keyboard_type("Hello, World!")
browser.keyboard_press_enter()
browser.mouse_click_selector("#submit-button")

Close the browser

browser.close()

Custom Chrome startup

You can also customize the Chrome startup:

# Start Chrome with custom options
Browser.start(
    path="/path/to/chrome",  # Custom Chrome executable path
    minimized=False,         # Start Chrome in normal window (not minimized)
    debug_port=9223          # Use a custom debugging port
)
browser = Browser(debug_port=9222)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

browsinator-0.1.2.tar.gz (5.5 kB view hashes)

Uploaded Source

Built Distribution

browsinator-0.1.2-py3-none-any.whl (5.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page