Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

added pyotp dependency and 2fa code generation

Maxim Kopeckic386fc9bcc73
diff --git a/browser_use/controller/registry/service.py b/browser_use/controller/registry/service.py
index 678ce13da..a20e41d7a 100644
--- a/browser_use/controller/registry/service.py
+++ b/browser_use/controller/registry/service.py
@@ -24,6 +24,8 @@ from browser_use.observability import observe_debug
from browser_use.telemetry.service import ProductTelemetry
from browser_use.utils import is_new_tab_page, match_url_with_domain_pattern, time_execution_async
+import pyotp
+
Context = TypeVar('Context')
logger = logging.getLogger(__name__)
@@ -444,6 +446,12 @@ class Registry(Generic[Context]):
for placeholder in matches:
if placeholder in applicable_secrets:
+
+ # generate a totp code if secret is a 2fa secret
+ if "otp_key" in placeholder:
+ totp = pyotp.TOTP(applicable_secrets[placeholder], digits=6)
+ applicable_secrets[placeholder] = totp.now()
+
value = value.replace(f'<secret>{placeholder}</secret>', applicable_secrets[placeholder])
replaced_placeholders.add(placeholder)
else:
diff --git a/pyproject.toml b/pyproject.toml
index 26d6ac42f..9cbb1a3d5 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -42,6 +42,7 @@ dependencies = [
"mcp>=1.10.1",
"pypdf>=5.7.0",
"markdown-pdf==1.5",
+ "pyotp>=2.9.0",
]
# google-api-core: only used for Google LLM APIs
# pyperclip: only used for examples that use copy/paste