mirror of
https://forge.fsky.io/oneflux/omegafox.git
synced 2026-02-10 19:52:04 -08:00
pythonlib: Add "test" CLI to open Playwright inspector
This commit is contained in:
parent
4eb559f043
commit
f45852c579
2 changed files with 45 additions and 7 deletions
|
|
@ -1,9 +1,12 @@
|
||||||
|
<div align="center">
|
||||||
|
|
||||||
# Camoufox Python Interface
|
# Camoufox Python Interface
|
||||||
|
|
||||||
#### Lightweight wrapper around the Playwright API to help launch Camoufox.
|
#### Lightweight wrapper around the Playwright API to help launch Camoufox.
|
||||||
|
|
||||||
> [!WARNING]
|
</div>
|
||||||
> This is still experimental and in active development!
|
|
||||||
|
---
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|
@ -29,6 +32,24 @@ python3 -m camoufox fetch
|
||||||
|
|
||||||
To uninstall, run `camoufox remove`.
|
To uninstall, run `camoufox remove`.
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>CLI options</summary>
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: python -m camoufox [OPTIONS] COMMAND [ARGS]...
|
||||||
|
|
||||||
|
Options:
|
||||||
|
--help Show this message and exit.
|
||||||
|
|
||||||
|
Commands:
|
||||||
|
fetch Fetch the latest version of Camoufox
|
||||||
|
remove Remove all downloaded files
|
||||||
|
test Open the Playwright inspector
|
||||||
|
version Display the current version
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
<hr width=50>
|
<hr width=50>
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
"""
|
"""
|
||||||
Binary CLI manager for Camoufox.
|
CLI package manager for Camoufox.
|
||||||
|
|
||||||
Adapted from https://github.com/daijro/hrequests/blob/main/hrequests/__main__.py
|
Adapted from https://github.com/daijro/hrequests/blob/main/hrequests/__main__.py
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from importlib.metadata import PackageNotFoundError
|
from importlib.metadata import PackageNotFoundError
|
||||||
from importlib.metadata import version as pkg_version
|
from importlib.metadata import version as pkg_version
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
|
|
@ -22,12 +23,13 @@ class CamoufoxUpdate(CamoufoxFetcher):
|
||||||
Initializes the CamoufoxUpdate class
|
Initializes the CamoufoxUpdate class
|
||||||
"""
|
"""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
self.current_verstr: Optional[str]
|
||||||
try:
|
try:
|
||||||
self.current_verstr = installed_verstr()
|
self.current_verstr = installed_verstr()
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
self.current_verstr = None
|
self.current_verstr = None
|
||||||
|
|
||||||
def is_updated_needed(self) -> None:
|
def is_updated_needed(self) -> bool:
|
||||||
if self.current_verstr is None:
|
if self.current_verstr is None:
|
||||||
return True
|
return True
|
||||||
# If the installed version is not the latest version
|
# If the installed version is not the latest version
|
||||||
|
|
@ -37,7 +39,7 @@ class CamoufoxUpdate(CamoufoxFetcher):
|
||||||
|
|
||||||
def update(self) -> None:
|
def update(self) -> None:
|
||||||
"""
|
"""
|
||||||
Updates the library if needed
|
Updates Camoufox if needed
|
||||||
"""
|
"""
|
||||||
# Check if the version is the same as the latest available version
|
# Check if the version is the same as the latest available version
|
||||||
if not self.is_updated_needed():
|
if not self.is_updated_needed():
|
||||||
|
|
@ -74,12 +76,27 @@ def fetch() -> None:
|
||||||
@cli.command(name='remove')
|
@cli.command(name='remove')
|
||||||
def remove() -> None:
|
def remove() -> None:
|
||||||
"""
|
"""
|
||||||
Remove all library files
|
Remove all downloaded files
|
||||||
"""
|
"""
|
||||||
if not CamoufoxUpdate().cleanup():
|
if not CamoufoxUpdate().cleanup():
|
||||||
rprint("Camoufox binaries not found!", fg="red")
|
rprint("Camoufox binaries not found!", fg="red")
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command(name='test')
|
||||||
|
@click.argument('url', default=None, required=False)
|
||||||
|
def test(url: Optional[str] = None) -> None:
|
||||||
|
"""
|
||||||
|
Open the Playwright inspector
|
||||||
|
"""
|
||||||
|
from .sync_api import Camoufox
|
||||||
|
|
||||||
|
with Camoufox(headless=False) as browser:
|
||||||
|
page = browser.new_page()
|
||||||
|
if url:
|
||||||
|
page.goto(url)
|
||||||
|
page.pause() # Open the Playwright inspector
|
||||||
|
|
||||||
|
|
||||||
@cli.command(name='version')
|
@cli.command(name='version')
|
||||||
def version() -> None:
|
def version() -> None:
|
||||||
"""
|
"""
|
||||||
|
|
@ -101,7 +118,7 @@ def version() -> None:
|
||||||
# Print the base version
|
# Print the base version
|
||||||
rprint(f"Camoufox:\tv{bin_ver} ", fg="green", nl=False)
|
rprint(f"Camoufox:\tv{bin_ver} ", fg="green", nl=False)
|
||||||
|
|
||||||
# Check for library updates
|
# Check for Camoufox updates
|
||||||
if updater.is_updated_needed():
|
if updater.is_updated_needed():
|
||||||
rprint(f"(Latest: v{updater.verstr})", fg="red")
|
rprint(f"(Latest: v{updater.verstr})", fg="red")
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue