Allow different browsers

This commit is contained in:
Bo Peng
2025-11-03 23:16:22 -06:00
parent e3959a275c
commit 236a2c719a
6 changed files with 1258 additions and 1225 deletions

View File

@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
## [0.9.11]
- [Issue 264](https://github.com/BoPeng/ai-marketplace-monitor/pull/264). Support different browsers.
## [0.9.10] ## [0.9.10]

View File

@@ -1,7 +1,7 @@
[project] [project]
readme = "README.md" readme = "README.md"
name = "ai-marketplace-monitor" name = "ai-marketplace-monitor"
version = "0.9.10" version = "0.9.11"
description = "An AI-based tool for monitoring facebook marketplace" description = "An AI-based tool for monitoring facebook marketplace"
authors = [{ name = "Bo Peng", email = "ben.bob@gmail.com" }] authors = [{ name = "Bo Peng", email = "ben.bob@gmail.com" }]
requires-python = ">=3.10" requires-python = ">=3.10"
@@ -47,6 +47,7 @@ Documentation = "https://ai-marketplace-monitor.readthedocs.io"
[project.scripts] [project.scripts]
ai-marketplace-monitor = "ai_marketplace_monitor.cli:app" ai-marketplace-monitor = "ai_marketplace_monitor.cli:app"
aimm = "ai_marketplace_monitor.cli:app"
[project.optional-dependencies] [project.optional-dependencies]
pynput = ["pynput>=1.7.0"] pynput = ["pynput>=1.7.0"]

View File

@@ -2,4 +2,4 @@
__author__ = """Bo Peng""" __author__ = """Bo Peng"""
__email__ = "ben.bob@gmail.com" __email__ = "ben.bob@gmail.com"
__version__ = "0.9.10" __version__ = "0.9.11"

View File

@@ -87,6 +87,35 @@ class MarketplaceMonitor:
doze(60, self.config_files, self.keyboard_monitor) doze(60, self.config_files, self.keyboard_monitor)
continue continue
def _launch_browser(self: "MarketplaceMonitor") -> Browser:
"""Launch a browser, preferring Chromium if available, otherwise any installed browser."""
# Try browsers in order of preference
browser_types = [
("chromium", self.playwright.chromium),
("firefox", self.playwright.firefox),
("webkit", self.playwright.webkit),
]
for browser_name, browser_type in browser_types:
try:
if self.logger:
self.logger.debug(f"Attempting to launch {browser_name} browser...")
browser = browser_type.launch(headless=self.headless)
if self.logger:
self.logger.info(
f"""{hilight("[Browser]", "info")} Successfully launched {browser_name} browser."""
)
return browser
except Exception as e:
if self.logger:
self.logger.debug(f"Failed to launch {browser_name}: {e}")
continue
# If all fail, raise an error
raise RuntimeError(
"No browser could be launched. Please ensure Chromium, Firefox, or WebKit is installed."
)
def load_ai_agents(self: "MarketplaceMonitor") -> None: def load_ai_agents(self: "MarketplaceMonitor") -> None:
"""Load the AI agent.""" """Load the AI agent."""
assert self.config is not None assert self.config is not None
@@ -394,7 +423,7 @@ class MarketplaceMonitor:
# Open a new browser page. # Open a new browser page.
self.load_config_file() self.load_config_file()
assert self.config is not None assert self.config is not None
self.browser = self.playwright.chromium.launch(headless=self.headless) self.browser = self._launch_browser()
# #
assert self.browser is not None assert self.browser is not None
while True: while True:
@@ -550,7 +579,7 @@ class MarketplaceMonitor:
self.logger.info( self.logger.info(
f"""{hilight("[Search]", "info")} Starting a browser because the item was not checked before.""" f"""{hilight("[Search]", "info")} Starting a browser because the item was not checked before."""
) )
self.browser = self.playwright.chromium.launch(headless=self.headless) self.browser = self._launch_browser()
marketplace.set_browser(self.browser) marketplace.set_browser(self.browser)
# ignore enabled # ignore enabled

View File

@@ -13,7 +13,7 @@ from ai_marketplace_monitor.user import User
def test_version(version: str) -> None: def test_version(version: str) -> None:
"""Sample pytest test function with the pytest fixture as an argument.""" """Sample pytest test function with the pytest fixture as an argument."""
assert version == "0.9.10" assert version == "0.9.11"
def test_listing_cache(temp_cache: Cache, listing: Listing) -> None: def test_listing_cache(temp_cache: Cache, listing: Listing) -> None:

2440
uv.lock generated
View File

File diff suppressed because it is too large Load Diff