Changed from user specific, to open for everyone
This commit is contained in:
@@ -72,6 +72,54 @@ def detect_browser_from_profile(profile_path: str) -> str | None:
|
||||
return None
|
||||
|
||||
|
||||
def find_firefox_profile() -> str | None:
|
||||
"""Auto-detect Firefox profile directory cross-platform."""
|
||||
import sys
|
||||
home = os.path.expanduser("~")
|
||||
candidates = []
|
||||
|
||||
if sys.platform == "win32":
|
||||
appdata = os.environ.get("APPDATA", "")
|
||||
if appdata:
|
||||
profiles_dir = os.path.join(appdata, "Mozilla", "Firefox", "Profiles")
|
||||
else:
|
||||
profiles_dir = os.path.join(home, "AppData", "Roaming", "Mozilla", "Firefox", "Profiles")
|
||||
elif sys.platform == "darwin":
|
||||
profiles_dir = os.path.join(home, "Library", "Application Support", "Firefox", "Profiles")
|
||||
else:
|
||||
profiles_dir = os.path.join(home, ".mozilla", "firefox")
|
||||
|
||||
if os.path.isdir(profiles_dir):
|
||||
for entry in os.listdir(profiles_dir):
|
||||
full = os.path.join(profiles_dir, entry)
|
||||
if os.path.isdir(full) and (".default" in entry.lower() or ".dev-edition" in entry.lower()):
|
||||
candidates.append(full)
|
||||
candidates.sort(key=lambda p: "default-release" in p.lower(), reverse=True)
|
||||
if candidates:
|
||||
logger.info("Auto-detected Firefox profile: %s", candidates[0])
|
||||
return candidates[0]
|
||||
return None
|
||||
|
||||
|
||||
def find_chrome_profile() -> str | None:
|
||||
"""Auto-detect Chrome/Chromium profile directory cross-platform."""
|
||||
import sys
|
||||
home = os.path.expanduser("~")
|
||||
|
||||
if sys.platform == "win32":
|
||||
base = os.path.join(os.environ.get("LOCALAPPDATA", ""), "Google", "Chrome", "User Data")
|
||||
elif sys.platform == "darwin":
|
||||
base = os.path.join(home, "Library", "Application Support", "Google", "Chrome")
|
||||
else:
|
||||
base = os.path.join(home, ".config", "google-chrome")
|
||||
|
||||
default_profile = os.path.join(base, "Default")
|
||||
if os.path.isdir(default_profile):
|
||||
logger.info("Auto-detected Chrome profile: %s", default_profile)
|
||||
return default_profile
|
||||
return None
|
||||
|
||||
|
||||
def copy_firefox_profile(src_path: str) -> str:
|
||||
"""Copy essential Firefox profile files to a temp dir for Playwright."""
|
||||
essential = ['cookies.sqlite', 'webappsstore.sqlite', 'permissions.sqlite']
|
||||
@@ -745,12 +793,27 @@ def cleanup_chrome():
|
||||
async def scrape_facebook(profile_path: str | None = None, force: bool = False) -> dict:
|
||||
"""Dispatcher — Firefox primary, browser-use Agent fallback."""
|
||||
effective_path = profile_path or FX_PROFILE
|
||||
|
||||
# Auto-detect Firefox profile if none provided
|
||||
if not effective_path:
|
||||
detected = find_firefox_profile()
|
||||
if detected:
|
||||
effective_path = detected
|
||||
os.environ["FX_PROFILE"] = detected
|
||||
|
||||
browser_type = detect_browser_from_profile(effective_path)
|
||||
|
||||
if not browser_type and CHROME_PROFILE:
|
||||
browser_type = detect_browser_from_profile(CHROME_PROFILE)
|
||||
effective_path = CHROME_PROFILE
|
||||
|
||||
# Auto-detect Chrome profile if still nothing
|
||||
if not browser_type:
|
||||
detected_chrome = find_chrome_profile()
|
||||
if detected_chrome:
|
||||
effective_path = detected_chrome
|
||||
browser_type = 'chromium'
|
||||
|
||||
logger.info("Detected browser: %s (profile: %s)", browser_type or "none", effective_path)
|
||||
|
||||
# Firefox primary (raw Playwright, stealth)
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
fastapi>=0.115.0
|
||||
uvicorn>=0.34.0
|
||||
playwright>=1.49.0
|
||||
browser-use>=0.1.0
|
||||
langchain-ollama>=0.2.0
|
||||
Reference in New Issue
Block a user