https://github.com/roniemartinez/browsers
Python library for detecting and launching browsers
https://github.com/roniemartinez/browsers
browser python
Last synced: 6 months ago
JSON representation
Python library for detecting and launching browsers
- Host: GitHub
- URL: https://github.com/roniemartinez/browsers
- Owner: roniemartinez
- License: mit
- Created: 2022-04-11T22:12:31.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2025-04-01T15:11:03.000Z (7 months ago)
- Last Synced: 2025-04-02T16:06:36.003Z (7 months ago)
- Topics: browser, python
- Language: Python
- Homepage:
- Size: 365 KB
- Stars: 27
- Watchers: 2
- Forks: 3
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
License
![]()
Version
![]()
Github Actions
![]()
Coverage
![]()
Supported versions
![]()
Wheel
![]()
Status
![]()
Downloads
![]()
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
```bash
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
```python
import browsers
```### List all installed browsers
```python
import browsersprint(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
```python
import browsersprint(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
```python
import browsersbrowsers.launch("chrome")
```### Launch browser with URL
```python
import browsersbrowsers.launch("chrome", url="https://github.com/roniemartinez/browsers")
```### Launch browser with arguments
```python
import browsersbrowsers.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.```python
import browsersprint(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
- [httptoolkit/browser-launcher](https://github.com/httptoolkit/browser-launcher)
- [Desktop Entry Specification](https://specifications.freedesktop.org/desktop-entry-spec/latest/)
- [Github: webbrowser.open incomplete on Windows](https://github.com/python/cpython/issues/52479#issuecomment-1093496412)
- [Stackoverflow: Grabbing full file version of an exe in Python](https://stackoverflow.com/a/68774871/1279157)## Contributors ✨
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
Ronie Martinez
💻 🤔 📖 🚧
Sergey Pirogov
🐛
vanderboon
💻
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!