Skip to content

Latest commit

 

History

History
78 lines (56 loc) · 1.68 KB

README.md

File metadata and controls

78 lines (56 loc) · 1.68 KB

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)