Skip to main content

Python library for detecting and launching browsers

Project description

License License Version Version
Github Actions Github Actions Coverage CodeCov
Supported versions Python Versions Wheel Wheel
Status Status Downloads Downloads
All Contributors All Contributors

browsers

Python library for detecting and launching browsers

Why?

I recently wrote a snippet for detecting installed browsers in an OSX machine in https://github.com/mitmproxy/mitmproxy/issues/5247#issuecomment-1095337723 based on https://github.com/httptoolkit/browser-launcher and I thought this could be useful to other devs since I cannot find an equivalent library of httptoolkit/browser-launcher in Python and the known webbrowser standard library does not support arguments.

Installation

pip install pybrowsers

Features

  • Detect browser on OSX
  • Detect browser on Linux
  • Detect browser on Windows
  • Launch browser with arguments
  • Launch and get browser by version with wildcard support

Usage

Import

import browsers

List all installed browsers

import browsers

print(list(browsers.browsers()))
# [{'browser_type': 'chrome', 'path': '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', 'display_name': 'Google Chrome', 'version': '100.0.4896.127'}, {'browser_type': 'firefox', 'path': '/Applications/Firefox.app/Contents/MacOS/firefox', 'display_name': 'Firefox', 'version': '99.0.1'}, {'browser_type': 'safari', 'path': '/Applications/Safari.app/Contents/MacOS/Safari', 'display_name': 'Safari', 'version': '15.4'}, {'browser_type': 'opera', 'path': '/Applications/Opera.app/Contents/MacOS/Opera', 'display_name': 'Opera', 'version': '85.0.4341.60'}, {'browser_type': 'msedge', 'path': '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge', 'display_name': 'Microsoft Edge', 'version': '100.1185.22042050'}]

Get browser information

import browsers

print(browsers.get("chrome"))
# {'browser_type': 'chrome', 'path': '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', 'display_name': 'Google Chrome', 'version': '100.0.4896.127'}

Launch browser

import browsers

browsers.launch("chrome")

Launch browser with URL

import browsers

browsers.launch("chrome", url="https://github.com/roniemartinez/browsers")

Launch browser with arguments

import browsers

browsers.launch("chrome", args=["--incognito"])

Specifying version

The get() and launch() functions support specifying version in case multiple versions are installed. Wildcard pattern is also supported.

import browsers

print(browsers.get("chrome", version="100.0.4896.127"))  # complete version
# {'browser_type': 'chrome', 'path': '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', 'display_name': 'Google Chrome', 'version': '100.0.4896.127'}

print(browsers.get("chrome", version="100.*"))  # wildcard
# {'browser_type': 'chrome', 'path': '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', 'display_name': 'Google Chrome', 'version': '100.0.4896.127'}

browsers.launch("chrome", version="100.0.4896.127")  # complete version
browsers.launch("chrome", version="100.*")  # wildcard

References

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Ronie Martinez

💻 🤔 📖 🚧

Sergey Pirogov

🐛

This project follows the all-contributors specification. Contributions of any kind welcome!

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

pybrowsers-0.6.0.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

pybrowsers-0.6.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file pybrowsers-0.6.0.tar.gz.

File metadata

  • Download URL: pybrowsers-0.6.0.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.5.0-1021-azure

File hashes

Hashes for pybrowsers-0.6.0.tar.gz
Algorithm Hash digest
SHA256 b683fd6fd308d07a285428da7cb025c6684922ef78c42b12dc4dd06b538b5473
MD5 5cc28e4a0f33d2d5679111a65c7fe202
BLAKE2b-256 127311f9a84df5fdc5d88b33b992af9a6caf96e09ad84cf3c0026f76af0e1bac

See more details on using hashes here.

File details

Details for the file pybrowsers-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: pybrowsers-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.5.0-1021-azure

File hashes

Hashes for pybrowsers-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2c672148462bf0daca0ff5fece24c1bfde7370277fecdadf313d5249f9b91ca6
MD5 dd47c096e41bd094bcf1c56af7d45481
BLAKE2b-256 2c175979276ec9973c0c87ce501013d41878a422d662d174ad41dc79668359af

See more details on using hashes here.

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