added_extension_support_in_browser_context (#2038)

Co-authored-by: Suchintan <suchintan@users.noreply.github.com>
This commit is contained in:
Piyush
2025-04-06 10:20:30 +05:30
committed by GitHub
parent 7e5e684f53
commit 8d93ded199
2 changed files with 19 additions and 0 deletions

View File

@@ -75,6 +75,10 @@ class Settings(BaseSettings):
BROWSER_WIDTH: int = 1920
BROWSER_HEIGHT: int = 1080
# Add extension folders name here to load extension in your browser
EXTENSIONS_BASE_PATH: str = "./extensions"
EXTENSIONS: list[str] = []
# Workflow constant parameters
WORKFLOW_DOWNLOAD_DIRECTORY_PARAMETER_KEY: str = "SKYVERN_DOWNLOAD_DIRECTORY"
WORKFLOW_WAIT_BLOCK_MAX_SEC: int = 30 * 60

View File

@@ -170,6 +170,16 @@ class BrowserContextFactory:
f"{settings.HAR_PATH}/{datetime.utcnow().strftime('%Y-%m-%d')}/{BrowserContextFactory.get_subdir()}.har"
)
extension_paths = []
if settings.EXTENSIONS and settings.EXTENSIONS_BASE_PATH:
try:
os.makedirs(settings.EXTENSIONS_BASE_PATH, exist_ok=True)
extension_paths = [str(Path(settings.EXTENSIONS_BASE_PATH) / ext) for ext in settings.EXTENSIONS]
LOG.info("Extensions paths constructed", extension_paths=extension_paths)
except Exception as e:
LOG.error("Error constructing extension paths", error=str(e))
browser_args = [
"--disable-blink-features=AutomationControlled",
"--disk-cache-size=1",
@@ -180,6 +190,11 @@ class BrowserContextFactory:
if cdp_port:
browser_args.append(f"--remote-debugging-port={cdp_port}")
if extension_paths:
joined_paths = ",".join(extension_paths)
browser_args.extend([f"--disable-extensions-except={joined_paths}", f"--load-extension={joined_paths}"])
LOG.info("Extensions added to browser args", extensions=joined_paths)
args = {
"locale": settings.BROWSER_LOCALE,
"color_scheme": "no-preference",