Skip to content

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

Notifications You must be signed in to change notification settings

slava-vishnyakov/browsinator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages